]> git.donarmstrong.com Git - mothur.git/blobdiff - chimera.cpp
latest version
[mothur.git] / chimera.cpp
index 692a4fee837376232981cfaf91934b96b5efa75d..3ab95892b9df8d1ad9692c2bca8b413412d3e0e5 100644 (file)
@@ -31,6 +31,8 @@ string Chimera::createFilter(vector<Sequence*> seqs, float t) {
                        if (m->control_pressed) { return filterString; }
                
                        string seqAligned = seqs[i]->getAligned();
+                       
+                       if (seqAligned.length() != filterString.length()) {  m->mothurOut(seqs[i]->getName() + " is not the same length as the template sequences. Aborting!\n");  exit(1); }
                
                        for (int j = 0; j < seqAligned.length(); j++) {
                                //if this spot is a gap
@@ -101,29 +103,37 @@ vector<Sequence*> Chimera::readSeqs(string file) {
                m->mothurOut("Reading sequences from " + file + "..."); cout.flush();
                
                #ifdef USE_MPI  
-                       int pid;
+                       int pid, processors;
                        vector<long> positions;
                        int numSeqs;
+                       int tag = 2001;
                
                        MPI_Status status; 
                        MPI_File inMPI;
                        MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
-       
-                       char inFileName[file.length()];
+                       MPI_Comm_size(MPI_COMM_WORLD, &processors);
+
+                       //char* inFileName = new char[file.length()];
+                       //memcpy(inFileName, file.c_str(), file.length());
+                       
+                       char inFileName[1024];
                        strcpy(inFileName, file.c_str());
        
                        MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
-       
+                       //delete inFileName;
+
                        if (pid == 0) {
                                positions = setFilePosFasta(file, numSeqs); //fills MPIPos, returns numSeqs
 
                                //send file positions to all processes
-                               MPI_Bcast(&numSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD);  //send numSeqs
-                               MPI_Bcast(&positions[0], (numSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //send file pos     
+                               for(int i = 1; i < processors; i++) { 
+                                       MPI_Send(&numSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
+                                       MPI_Send(&positions[0], (numSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
+                               }
                        }else{
-                               MPI_Bcast(&numSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD); //get numSeqs
+                               MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
                                positions.resize(numSeqs+1);
-                               MPI_Bcast(&positions[0], (numSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //get file positions
+                               MPI_Recv(&positions[0], (numSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
                        }
                        
                        //read file 
@@ -133,12 +143,14 @@ vector<Sequence*> Chimera::readSeqs(string file) {
        
                                //read next sequence
                                int seqlength = positions[i+1] - positions[i];
-                               char buf4[seqlength];
+                               char* buf4 = new char[seqlength];
+
                                MPI_File_read_at(inMPI, positions[i], buf4, seqlength, MPI_CHAR, &status);
                                
                                string tempBuf = buf4;
                                if (tempBuf.length() > seqlength) { tempBuf = tempBuf.substr(0, seqlength); }
-                               
+                               delete buf4;
+
                                istringstream iss (tempBuf,istringstream::in);
                
                                Sequence* current = new Sequence(iss);   
@@ -151,6 +163,7 @@ vector<Sequence*> Chimera::readSeqs(string file) {
                        }
                        
                        MPI_File_close(&inMPI);
+                       MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
        #else
 
                ifstream in;
@@ -196,18 +209,25 @@ void Chimera::setMask(string filename) {
                        MPI_Offset size;
                        MPI_Status status;
                        
-                       char inFileName[filename.length()];
+                       //char* inFileName = new char[filename.length()];
+                       //memcpy(inFileName, filename.c_str(), filename.length());
+                       
+                       char inFileName[1024];
                        strcpy(inFileName, filename.c_str());
        
                        MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
                        MPI_File_get_size(inMPI, &size);
+
+                       //delete inFileName;
                        
-                       char buffer[size];
+                       char* buffer = new char[size];
                        MPI_File_read(inMPI, buffer, size, MPI_CHAR, &status);
                        
                        string tempBuf = buffer;
                        if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size);  }
                        istringstream iss (tempBuf,istringstream::in);
+
+                       delete buffer;
                        
                        if (!iss.eof()) {
                                Sequence temp(iss);