]> git.donarmstrong.com Git - mothur.git/blobdiff - aligncommand.cpp
fixed bug in cluster.split
[mothur.git] / aligncommand.cpp
index a4b3a79012aa5ac0d53c6ff78f541864984b42ec..c5407ca345a2ff7bdec2ed47089f7e10d1df1fc3 100644 (file)
@@ -266,19 +266,31 @@ int AlignCommand::execute(){
                                
                                int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY; 
                                int inMode=MPI_MODE_RDONLY; 
-                                                               
-                               char outAlignFilename[alignFileName.length()];
+                               
+                               //char* outAlignFilename = new char[alignFileName.length()];
+                               //memcpy(outAlignFilename, alignFileName.c_str(), alignFileName.length());
+                               
+                               char outAlignFilename[1024];
                                strcpy(outAlignFilename, alignFileName.c_str());
+
+                               //char* outReportFilename = new char[reportFileName.length()];
+                               //memcpy(outReportFilename, reportFileName.c_str(), reportFileName.length());
                                
-                               char outReportFilename[reportFileName.length()];
+                               char outReportFilename[1024];
                                strcpy(outReportFilename, reportFileName.c_str());
+
+                               //char* outAccnosFilename = new char[accnosFileName.length()];
+                               //memcpy(outAccnosFilename, accnosFileName.c_str(), accnosFileName.length());
                                
-                               char outAccnosFilename[accnosFileName.length()];
+                               char outAccnosFilename[1024];
                                strcpy(outAccnosFilename, accnosFileName.c_str());
+
+                               //char* inFileName = new char[candidateFileNames[s].length()];
+                               //memcpy(inFileName, candidateFileNames[s].c_str(), candidateFileNames[s].length());
                                
-                               char inFileName[candidateFileNames[s].length()];
+                               char inFileName[1024];
                                strcpy(inFileName, candidateFileNames[s].c_str());
-
+                               
                                MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
                                MPI_File_open(MPI_COMM_WORLD, outAlignFilename, outMode, MPI_INFO_NULL, &outMPIAlign);
                                MPI_File_open(MPI_COMM_WORLD, outReportFilename, outMode, MPI_INFO_NULL, &outMPIReport);
@@ -291,13 +303,16 @@ int AlignCommand::execute(){
                                        MPIPos = setFilePosFasta(candidateFileNames[s], numFastaSeqs); //fills MPIPos, returns numSeqs
                                        
                                        //send file positions to all processes
-                                       MPI_Bcast(&numFastaSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD);  //send numSeqs
-                                       MPI_Bcast(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //send file pos   
+                                       for(int i = 1; i < processors; i++) { 
+                                               MPI_Send(&numFastaSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
+                                               MPI_Send(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
+                                       }
                                        
                                        //figure out how many sequences you have to align
                                        numSeqsPerProcessor = numFastaSeqs / processors;
-                                       if(pid == (processors - 1)){    numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor;         }
                                        int startIndex =  pid * numSeqsPerProcessor;
+                                       if(pid == (processors - 1)){    numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor;         }
+                                       
                                
                                        //align your part
                                        driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIAlign, outMPIReport, outMPIAccnos, MPIPos);
@@ -310,14 +325,16 @@ int AlignCommand::execute(){
                                                if (tempResult != 0) { MPIWroteAccnos = true; }
                                        }
                                }else{ //you are a child process
-                                       MPI_Bcast(&numFastaSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD); //get numSeqs
+                                       MPI_Recv(&numFastaSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
                                        MPIPos.resize(numFastaSeqs+1);
-                                       MPI_Bcast(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //get file positions
+                                       MPI_Recv(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
+
                                        
                                        //figure out how many sequences you have to align
                                        numSeqsPerProcessor = numFastaSeqs / processors;
-                                       if(pid == (processors - 1)){    numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor;         }
                                        int startIndex =  pid * numSeqsPerProcessor;
+                                       if(pid == (processors - 1)){    numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor;         }
+                                       
                                        
                                        //align your part
                                        driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIAlign, outMPIReport, outMPIAccnos, MPIPos);
@@ -647,10 +664,13 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
                if (pid == 0) {
                        outputString = report.getHeaders();
                        int length = outputString.length();
-                       char buf[length];
-                       strcpy(buf, outputString.c_str()); 
+            
+                       char* buf = new char[length];
+                       memcpy(buf, outputString.c_str(), length);
                
                        MPI_File_write_shared(reportFile, buf, length, MPI_CHAR, &statusReport);
+
+            delete buf;
                }
                
                for(int i=0;i<num;i++){
@@ -659,10 +679,16 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
 
                        //read next sequence
                        int length = MPIPos[start+i+1] - MPIPos[start+i];
-                       char buf4[length];
+
+                       char* buf4 = new char[length];
+                       memcpy(buf4, outputString.c_str(), length);
+
                        MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
                        
                        string tempBuf = buf4;
+
+                       delete buf4;
+
                        if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length);  }
                        istringstream iss (tempBuf,istringstream::in);
        
@@ -727,10 +753,12 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
                                        
                                        //send results to parent
                                        int length = outputString.length();
-                                       char buf[length];
-                                       strcpy(buf, outputString.c_str()); 
+
+                                       char* buf = new char[length];
+                                       memcpy(buf, outputString.c_str(), length);
                                
                                        MPI_File_write_shared(accnosFile, buf, length, MPI_CHAR, &statusAccnos);
+                                       delete buf;
                                        MPIWroteAccnos = true;
                                }
                                
@@ -744,20 +772,23 @@ int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& align
                                
                                //send results to parent
                                int length = outputString.length();
-                               char buf2[length];
-                               strcpy(buf2, outputString.c_str()); 
+                               char* buf2 = new char[length];
+                               memcpy(buf2, outputString.c_str(), length);
                                
                                MPI_File_write_shared(alignFile, buf2, length, MPI_CHAR, &statusAlign);
                                
+                               delete buf2;
+
                                outputString = report.getReport();
                                
                                //send results to parent
                                length = outputString.length();
-                               char buf3[length];
-                               strcpy(buf3, outputString.c_str()); 
+                               char* buf3 = new char[length];
+                               memcpy(buf3, outputString.c_str(), length);
                                
                                MPI_File_write_shared(reportFile, buf3, length, MPI_CHAR, &statusReport);
-
+                               
+                               delete buf3;
                                delete nast;
                                if (needToDeleteCopy) {   delete copy;   }
                        }