Implementation of Smith-waterman algorithm openmp + mpi

Source: Internet
Author: User

// This Smith-Waterman algorithm can be implemented using mpi and openmp respectively, but there will be various problems during mixed programming, what you want to understand is a clear path... Thank you very much.
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         /* File pointers */FILE * ptr_file_1, * ptr_file_2, * ptr_file_3; // test file pointers/* Definitions */# define TRUE 1 # define FALSE 0 # define Match 1 # define MissMatch-1 # define GapPenalty 2 # define MAXLEN 20/* Global Variables * /char inputC [5]; // user input characterint inputI; int StrLen1, StrLen2; int intcheck = TRUE; char holder, ch; int filelen1 = 0; int filelen2 = 0; int filelen3 = 0; int I, j, k, l, m, n, lenA, lenB, compv Al, top, left, left_top, rows, columns, contrl; char FASTA1 [MAXLEN], FASTA2 [MAXLEN]; char dash = '-'; char strA [MAXLEN]; // holds 1st string to be aligned in character arraychar strB [MAXLEN]; // holds 2nd string to be aligned in character array int HiScore; // holds value of highest scoring alignment (s ). int HiScorePos [2]; // the position of the HiScoreint SWArray [MAXLEN] [MAXLEN]; // S-W Matrixchar MaxA [MAXLEN]; Char MaxB [MAXLEN]; char OptA [MAXLEN]; char OptB [MAXLEN]; int MaxAcounter = 1; // MaxA counterint MaxBcounter = 1; // MaxB counterint cont = TRUE; int check; int rank, size; MPI_Status status; int buff [3];/* alignment function */int Align (int PosA, int PosB) {/* Function Variables */int relmax =-1; // hold highest value in sub columns and rowsint relmaxpos [2]; // holds position of relmaxif (SWArray [PosA-1] [PosB-1] = 0) {cont = FALSE;} while (cont = TRUE) {// until the diagonal of the current cell has a value of zero/* Find relmax in sub columns and rows */for (I = PosA; I> 0; -- I) {if (relmax <SWArray [I-1] [PosB-1]) {relmax = SWArray [I-1] [PosB-1]; relmaxpos [0] = I-1; relmaxpos [1] = PosB-1 ;}} for (j = PosB; j> 0; -- j) {if (relmax <SWArray [PosA-1] [J-1]) {relmax = SWArray [PosA-1] [J-1]; relmaxpos [0] = PosA-1; relmaxpos [1] = J-1;}/* Al Ign strings to relmax */if (relmaxpos [0] = PosA-1) & (relmaxpos [1] = PosB-1 )) {// if relmax position is diagonal from current position simply align and increment countersMaxA [MaxAcounter] = strA [relmaxpos [0]-1]; ++ MaxAcounter; maxB [MaxBcounter] = strB [relmaxpos [1]-1]; ++ MaxBcounter;} else {if (relmaxpos [1] = PosB-1) & (relmaxpos [0]! = PosA-1) {// maxB needs at least one '-' for (I = PosA-1; I> relmaxpos [0]-1; -- I) {// for all elements of strA between PosA and relmaxpos [0] MaxA [MaxAcounter] = strA [I-1]; ++ MaxAcounter;} for (j = PosA-1; j> relmaxpos [0]; -- j) {// set dashes to MaxB up to relmaxMaxB [MaxBcounter] = dash; ++ MaxBcounter ;} maxB [MaxBcounter] = strB [relmaxpos [1]-1]; // at relmax set pertinent strB value to MaxB ++ MaxBcounter;} if (relmaxpos [0] = PosA-1) & (relmaxpos [1]! = PosB-1) {// MaxA needs at least one '-' for (j = PosB-1; j> relmaxpos [1]-1; -- j) {// for all elements of strB between PosB and relmaxpos [1] MaxB [MaxBcounter] = strB [J-1]; ++ MaxBcounter;} for (I = PosB-1; i> relmaxpos [1]; -- I) {// set dashes to strAMaxA [MaxAcounter] = dash; ++ MaxAcounter ;} maxA [MaxAcounter] = strA [relmaxpos [0]-1]; ++ MaxAcounter ;}// printf ("(% I, % I)", relmaxpos [0], relmaxpos [1]); Align (relmaxpos [0], rel Maxpos [1]);} return (cont);} int SWMax (int num1, int num2, int num3) {int max =-1; if (num1> num2) {max = num1;} else if (num2> num3) {max = num2;} else {max = num3;} return max ;} /* main functions */int main (int argc, char ** argv) {MPI_Init (& argc, & argv); // MPI initializes MPI_Comm_rank (MPI_COMM_WORLD, & rank ); // obtain the current process ID MPI_Comm_size (MPI_COMM_WORLD, & size); // The total number of processes printf ("size = % d \ n", size ); /* open first file */ptr_file_1 = fopen ("d:/mpi /Str1.fa "," r ");/* check to see if it opened okay */if (ptr_file_1 = NULL) {printf (" Error opening 'str1. fa '\ n "); system (" PAUSE "); exit (8);}/* open second file */ptr_file_2 = fopen (" d:/mpi/str2.fa ", "r");/* check to see if it opened okay */if (ptr_file_2 = NULL) {printf ("Error opening 'str2. fa '\ n "); system (" PAUSE "); exit (8);}/* measure file1 length */while (holder! = EOF) {holder = fgetc (ptr_file_1); if (filelen1 <MAXLEN & holder! = EOF) {strA [filelen1] = holder; ++ filelen1 ;}} strA [filelen1] =-1; holder = '0 '; /* measure file2 length */while (holder! = EOF) {holder = fgetc (ptr_file_2); if (filelen2 <MAXLEN & holder! = EOF) {strB [filelen2] = holder; ++ filelen2 ;}} strB [filelen2] =-1; fclose (ptr_file_1); fclose (ptr_file_2 ); lenA = strlen (strA)-1; lenB = strlen (strB)-1; time_t t1 = time (NULL); printf ("t1 = % d \ n", t1 ); /* ---------------------------- problem code ** --------------------------- */for (contrl = 0; contrl
        
          0) {fprintf (ptr_file_3, "% c", strA [I-1]);} for (j = 0; j <= lenB; ++ j) {fprintf (ptr_file_3, "% 3i", SWArray [I] [j]);} fprintf (ptr_file_3, "\ n");} fclose (ptr_file_3 ); /* make alignmentt */for (I = 0; I <= lenA; ++ I) {// find highest score in matrix: this is the starting point of an optimal local alignmentfor (j = 0; j <= lenB; ++ j) {if (SWArray [I] [j]> HiScore) {HiScore = SWArray [I] [j]; HiScorePos [0] = I; HiScorePos [1] = j ;}}} // send Position to alignment functionMaxA [0] = strA [HiScorePos [0]-1]; MaxB [0] = strB [HiScorePos [1]-1]; check = Align (HiScorePos [0], HiScorePos [1]); // in the end reverse Max A and Bk = 0; for (I = strlen (MaxA)-1; i>-1; -- I) {OptA [k] = MaxA [I]; ++ k;} k = 0; for (j = strlen (MaxB)-1; j>-1; -- j) {OptB [k] = MaxB [j]; ++ k;} printf ("% s \ n", OptA, optB); time_t t2 = time (NULL); printf ("t2 = % d \ n", t2); printf ("Time-consuming is: % ds \ n ", (t2-t1); MPI_Finalize (); return (0 );}
        
       
      
     
    
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.