/* This is the program to compute Edit Distance Matrix * using the Edmiston's Algorithm on MultiProcessors. * This program will further be used as a sub-routine * to implement Heirschberg's Divide and Conquer Algorithm. * i.e a hybrid of Heirschberg and Edmiston's Algorithm. * * PLZ NOTE: This code uses upc_all_alloc() (Shared Ptrs) * and uses upc_barrier, which is suspected to * be causing problems because of its blocking * nature. * * * Author: Sirisha Muppavarapu */ #include #include #include #include #include #include #include #define iGapPen 2 #define iMatch 0 #define iMisMatch 1 /* Macro which determines the minimum of the two arguments */ #undef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) /* Macro which determines the maximum of the two arguments */ #undef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) /* Macro which determines the minimum of the three arguments */ #define MIN3(a,b,c) MIN(MIN((a),(b)),(c)) /* Macro which determines the maximum of the three arguments */ #define MAX3(a,b,c) MAX(MAX((a),(b)),(c)) /* Function Prototypes */ void initEditDistance(); void printEditDistance(char *cSeq1, char *cSeq2); void printCounter(); void initCounter(); void printSeq(char *cSeq); void findEditDist(char* cSeq1, char* cSeq2); int isMatch(char cChar1, char cChar2); int findMin(int iRow,int iCol,int iThreadNum,char *cSeq1,char *cSeq2); void initSeq(int iLen,char *cDest); /* Shared Variables */ shared[ ] int **iEditDist; shared int iCounter[THREADS]; shared int iMatRowSize,iMatColSize,iError; shared char *seqAG,*seqBG; /* Initialization of the EditDistance Matrix */ void initEditDistance() { int i,j=0; int iRowSize,iColSize; iRowSize = iMatRowSize; iColSize = iMatColSize; //iEditDist = (shared [ ] int**) upc_all_alloc(1,(iMatRowSize+1)*sizeof(shared int*)); iEditDist = (shared [ ] int**)malloc((iRowSize+1)*sizeof(shared [] int*)); for(i=0;i<=iRowSize;i++) //iEditDist[i]=(shared [ ] int*) upc_all_alloc(floor(iColSize/THREADS),(iColSize+1)*sizeof(int)); iEditDist[i]=(shared [ ] int*) upc_all_alloc(1,(iColSize+1)*sizeof(int)); upc_forall(i=0;i<=iRowSize;i++;i) for(j=0;j<=iColSize;j++) iEditDist[i][j] = 0; } /* Function to print the Edit Distance Matrix */ void printEditDistance(char *cSeq1, char *cSeq2){ int i=0,j=0,iRowSize,iColSize; iRowSize = iMatRowSize; iColSize = iMatColSize; printf("Matrix EditDistance is:\n"); printf(" %3c ",' '); printf(" %3c ",'-'); for(j=1;j<=iColSize;j++) printf(" %3c ",cSeq2[j-1]); printf("\n"); for(i=0;i<=iRowSize;i++){ if(i==0) printf(" %3c ",'-'); else printf(" %3c ",cSeq1[i-1]); for(j=0;j<=iColSize;j++) printf(" %3d ",iEditDist[i][j]); printf("\n"); } } /* Function to print the input sequences */ void printSeq(char *cSeq){ printf("The Given String is = %s\n", cSeq); } /* Function to initialize the shared counter */ void initCounter() { int i=0; for(i=0;i0) return iEditDist[iRow-1][iCol]+iGapPen; if(iRow==0 && iCol>0) return iEditDist[iRow][iCol-1]+iGapPen; if(iCol>0 && iRow>0) { iNorth = iEditDist[iRow-1][iCol]+iGapPen; iWest = iEditDist[iRow][iCol-1]+iGapPen; iNorthWest = iEditDist[iRow-1][iCol-1]+isMatch(cSeq1[iRow-1],cSeq2[iCol-1]); //iNorthWest = (iEditDist[iRow-1][iCol-1])+(cSeq1[iRow-1]==cSeq2[iCol-1] ? match : mismatch); } return MIN3(iNorth,iWest,iNorthWest); } void findEditDist(char* cSeq1, char* cSeq2) { int i,j,iColStart,iColEnd=0,iRow=0,iRowSize,iColSize; iRowSize = iMatRowSize; iColSize = iMatColSize; iColStart=MYTHREAD*floor(((iColSize+1)/THREADS)); if(MYTHREAD == THREADS-1){ iColEnd=iColSize+1; } else { iColEnd=(MYTHREAD+1)*floor(((iColSize+1)/THREADS)); } //printf("I am Thread %d, My Columns Range is %d to %d\n",MYTHREAD,iColStart,iColEnd); //upc_barrier; #if 0 /* DOB: this loop is incorrect because some threads exit the loop early while * others are still inside it performing barriers */ for(i=0;iCounter[MYTHREAD]