]> git.donarmstrong.com Git - mothur.git/commitdiff
added MPI to dist.seqs command
authorwestcott <westcott>
Fri, 12 Mar 2010 17:39:18 +0000 (17:39 +0000)
committerwestcott <westcott>
Fri, 12 Mar 2010 17:39:18 +0000 (17:39 +0000)
Mothur.xcodeproj/project.pbxproj
commandfactory.cpp
distancecommand.cpp
distancecommand.h
engine.cpp
filterseqscommand.cpp
filterseqscommand.h
mothur.cpp
mothurout.cpp
sequence.cpp

index e30c0d4acd457fb66f0a21b289853eb7578b310a..f07824e75ecdba89c37fddc31316861b23d958d8 100644 (file)
                                );
                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
+                               LINK_WITH_STANDARD_LIBRARIES = YES;
                                PREBINDING = NO;
                                SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
                        };
index b4f36549c0c65a22d0b2ad6057b9e07e294a4c65..727f6e821f019ae5c2f7629e1d0afabd33b6e789 100644 (file)
@@ -94,7 +94,7 @@ CommandFactory::CommandFactory(){
        commands["get.oturep"]                  = "get.oturep";
        commands["cluster"]                             = "cluster"; 
        commands["unique.seqs"]                 = "unique.seqs"; 
-       commands["dist.seqs"]                   = "dist.seqs";
+       commands["dist.seqs"]                   = "MPIEnabled";
        commands["dist.shared"]                 = "dist.shared";
        commands["collect.single"]              = "collect.single"; 
        commands["collect.shared"]              = "collect.shared"; 
index f05cb768e0c433daf1a976827b9371333e37acb7..23f2834648bb905ff2139c4bc05de59760e4729b 100644 (file)
@@ -166,7 +166,7 @@ int DistanceCommand::execute(){
                cutoff += 0.005;
                
                string outputFile;
-               
+                               
                if (output == "lt") { //does the user want lower triangle phylip formatted file 
                        outputFile = outputDir + getRootName(getSimpleName(fastafile)) + "phylip.dist";
                        remove(outputFile.c_str());
@@ -179,8 +179,64 @@ int DistanceCommand::execute(){
                        outputFile = outputDir + getRootName(getSimpleName(fastafile)) + "square.dist";
                        remove(outputFile.c_str());
                }
+               
+
+#ifdef USE_MPI
+               
+               int pid, start, end; 
+               int tag = 2001;
                                
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+               MPI_Status status; 
+               MPI_Comm_size(MPI_COMM_WORLD, &processors); //set processors to the number of mpi processes running
+               MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
+               
+               //each process gets where it should start and stop in the file
+               start = int (sqrt(float(pid)/float(processors)) * numSeqs);
+               end = int (sqrt(float(pid+1)/float(processors)) * numSeqs);
+               
+               if (pid == 0) { //you are the root process 
+                       //do your part
+                       string outputMyPart;
+                       driverMPI(start, end, outputMyPart, cutoff);
+                       
+                       ofstream out;
+                       openOutputFile(outputFile, out);
+                       
+                       out << outputMyPart;
+                       
+                       //get the childrens parts
+                       for(int i = 1; i < processors; i++) { 
+                               int length;
+                               MPI_Recv(&length, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status); 
+                               
+                               char buf[length];
+                                       
+                               MPI_Recv(buf, length, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status); 
+                               
+                               outputMyPart = buf;
+                               out << outputMyPart;
+                       }
+                       
+                       out.close();
+                       
+               }else { //you are a child process
+                       //do your part
+                       string outputMyPart;
+                       driverMPI(start, end, outputMyPart, cutoff);
+               
+                       //send results to parent
+                       int length = outputMyPart.length();
+                       char buf[length];
+                       strcpy(buf, outputMyPart.c_str()); 
+                       
+                       MPI_Send( &length, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
+                       MPI_Send(buf, length, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
+               }
+               
+
+#else          
+                               
+       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                //if you don't need to fork anything
                if(processors == 1){
                        driver(0, numSeqs, outputFile, cutoff);
@@ -204,14 +260,26 @@ int DistanceCommand::execute(){
                                remove((outputFile + toString(it->second) + ".temp").c_str());
                        }
                }
-#else
+       #else
                ifstream inFASTA;
                driver(0, numSeqs, outputFile, cutoff);
+       #endif
+       
 #endif
                if (m->control_pressed) { delete distCalculator; remove(outputFile.c_str()); return 0; }
                
+               #ifdef USE_MPI
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
+                                       
+                       if (pid == 0) { //only one process should output to screen
+               #endif
+               
                if (output == "square") {  convertMatrix(outputFile); }
                
+               #ifdef USE_MPI
+                       }
+               #endif
+               
                if (m->control_pressed) { delete distCalculator; remove(outputFile.c_str()); return 0; }
                
                delete distCalculator;
@@ -321,6 +389,62 @@ int DistanceCommand::driver(int startLine, int endLine, string dFileName, float
                exit(1);
        }
 }
+/**************************************************************************************************/
+/////// need to fix to work with calcs and sequencedb
+int DistanceCommand::driverMPI(int startLine, int endLine, string& outputString, float cutoff){
+       try {
+
+               int startTime = time(NULL);
+               
+               outputString = "";
+                               
+               if((output == "lt") && startLine == 0){ outputString += (toString(alignDB.getNumSeqs()) + '\n');        }
+               
+               for(int i=startLine;i<endLine;i++){
+       
+                       if(output == "lt")      {       
+                               string name = alignDB.get(i).getName();
+                               if (name.length() < 10) { //pad with spaces to make compatible
+                                       while (name.length() < 10) {  name += " ";  }
+                               }
+                               outputString += (name + '\t');  
+                       }
+                       for(int j=0;j<i;j++){
+                               
+                               if (m->control_pressed) {  return 0;  }
+                               
+                               distCalculator->calcDist(alignDB.get(i), alignDB.get(j));
+                               double dist = distCalculator->getDist();
+                               
+                               if(dist <= cutoff){
+                                       if (output == "column") { outputString += (alignDB.get(i).getName() + ' ' + alignDB.get(j).getName() + ' ' + toString(dist) + '\n'); }
+                               }
+                               if (output == "lt") {   outputString += (toString(dist) + '\t'); }
+                               
+                               if (output == "square") { //make a square column you can convert to square phylip
+                                       outputString += (alignDB.get(i).getName() + ' ' + alignDB.get(j).getName() + ' ' + toString(dist) + '\n');
+                                       outputString += (alignDB.get(j).getName() + ' ' + alignDB.get(i).getName() + ' ' + toString(dist) + '\n');
+                               }
+
+                       }
+                       
+                       if (output == "lt") { outputString += '\n'; }
+                       
+                       if(i % 100 == 0){
+                               m->mothurOut(toString(i) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine();
+                       }
+                       
+               }
+               m->mothurOut(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine();
+               
+               return 1;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "DistanceCommand", "driver");
+               exit(1);
+       }
+}
+
 /**************************************************************************************************/
 int DistanceCommand::convertMatrix(string outputFile) {
        try{
index 61fc49ea89b37e064c7d6446421efcf12251301a..3fa69d553ef857cb854e4ecfe9853ad36ecd2e0c 100644 (file)
@@ -46,6 +46,8 @@ private:
        //void appendFiles(string, string);
        void createProcesses(string);
        int driver(/*Dist*, SequenceDB, */int, int, string, float);
+       int driverMPI(int, int, string&, float);
+       
        int convertMatrix(string);
 
 };
index 2d5fd75959d479826f5239b364879ff316f4eaca..c6ceb59d051d6fb88fe1e169bdd9206da9d58ef8 100644 (file)
@@ -54,18 +54,8 @@ bool InteractEngine::getInput(){
                        mout->mothurOutEndLine();
                        
                        input = getCommand();   
-                       #ifdef USE_MPI
-                                       int pid;
-                                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                                       if (pid == 0) {
-                       #endif
                        mout->mothurOutEndLine();       
                        
-                       #ifdef USE_MPI
-                               }
-                       #endif
-                       
                        if (mout->control_pressed) { input = "quit()"; }
                        
                        //allow user to omit the () on the quit command
@@ -117,85 +107,26 @@ string Engine::getCommand()  {
                                if(nextCommand != NULL) {  add_history(nextCommand);  } 
                                else{ //^D causes null string and we want it to quit mothur
                                        nextCommand = "quit"; 
-                                       cout << nextCommand << endl;
+                                       mout->mothurOut(nextCommand);
                                }       
                                
-                               #ifdef USE_MPI
-                                       int pid;
-                                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                                       if (pid == 0) { //only one process should output to screen
-                               #endif
-
                                mout->mothurOutJustToLog("mothur > " + toString(nextCommand));
-                               
-                               #ifdef USE_MPI
-                                       }
-                               #endif
-                               
                                return nextCommand;
                        #else
                                string nextCommand = "";
-                               #ifdef USE_MPI
-                                       int pid;
-                                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                                       if (pid == 0) { //only one process should output to screen
-                               #endif
-
                                mout->mothurOut("mothur > ");
-                               
-                               #ifdef USE_MPI
-                                       }
-                               #endif
-                               
                                getline(cin, nextCommand);
-                               
-                               #ifdef USE_MPI
-                                       int pid;
-                                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                                       if (pid == 0) { //only one process should output to screen
-                               #endif
-                               
                                mout->mothurOutJustToLog("mothur > " + toString(nextCommand));
                                
-                               #ifdef USE_MPI
-                                       }
-                               #endif
-
                                return nextCommand;
                        #endif
                #else
-                       string nextCommand = "";
-                               #ifdef USE_MPI
-                                       int pid;
-                                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                                       if (pid == 0) { //only one process should output to screen
-                               #endif
-
-                               mout->mothurOut("mothur > ");
-                               
-                               #ifdef USE_MPI
-                                       }
-                               #endif
+                               string nextCommand = "";
                                
+                               mout->mothurOut("mothur > ");
                                getline(cin, nextCommand);
-                               
-                               #ifdef USE_MPI
-                                       int pid;
-                                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                                       if (pid == 0) { //only one process should output to screen
-                               #endif
-                               
                                mout->mothurOutJustToLog(toString(nextCommand));
                                
-                               #ifdef USE_MPI
-                                       }
-                               #endif
-
                                return nextCommand;
                #endif
                
@@ -252,21 +183,10 @@ bool BatchEngine::getInput(){
                        
                        if (input[0] != '#') {
                                
-                               #ifdef USE_MPI
-                                       int pid;
-                                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                                       if (pid == 0) { //only one process should output to screen
-                               #endif
-
                                mout->mothurOutEndLine();
                                mout->mothurOut("mothur > " + input);
                                mout->mothurOutEndLine();
-                               
-                               #ifdef USE_MPI
-                                       }
-                               #endif
-                               
+                                                       
                                if (mout->control_pressed) { input = "quit()"; }
                                
                                //allow user to omit the () on the quit command
@@ -354,21 +274,10 @@ bool ScriptEngine::getInput(){
                        
                        if (input == "") { input = "quit()"; }
                        
-                       #ifdef USE_MPI
-                                       int pid;
-                                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                                       if (pid == 0) {
-                       #endif
-
                        mout->mothurOutEndLine();
                        mout->mothurOut("mothur > " + input);
                        mout->mothurOutEndLine();
                        
-                       #ifdef USE_MPI
-                                       }
-                       #endif
-                       
                        if (mout->control_pressed) { input = "quit()"; }
                                
                        //allow user to omit the () on the quit command
index 326be01ff722fda90a61e0dd887f8d3e57107be4..aa38e7affa36e65ada9463813bfce76438c382fe 100644 (file)
@@ -131,13 +131,7 @@ FilterSeqsCommand::FilterSeqsCommand(string option)  {
 
 void FilterSeqsCommand::help(){
        try {
-               #ifdef USE_MPI
-                               int pid;
-                               MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                               if (pid == 0) {
-               #endif
-               
+                               
                m->mothurOut("The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file.\n");
                m->mothurOut("The filter.seqs command parameters are fasta, trump, soft, hard and vertical. \n");
                m->mothurOut("The fasta parameter is required. You may enter several fasta files to build the filter from and filter, by separating their names with -'s.\n");
@@ -151,10 +145,6 @@ void FilterSeqsCommand::help(){
                m->mothurOut("Example filter.seqs(fasta=abrecovery.fasta, trump=..., soft=..., hard=..., vertical=T).\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
                
-               #ifdef USE_MPI
-                       }
-               #endif
-               
        }
        catch(exception& e) {
                m->errorOut(e, "FilterSeqsCommand", "help");
@@ -232,13 +222,7 @@ int FilterSeqsCommand::execute() {
                
                if (m->control_pressed) {  for(int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }  return 0; }
 
-               #ifdef USE_MPI
-                               int pid;
-                               MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
-                                       
-                               if (pid == 0) {
-               #endif
-
+               
                m->mothurOutEndLine();
                m->mothurOut("Length of filtered alignment: " + toString(filteredLength)); m->mothurOutEndLine();
                m->mothurOut("Number of columns removed: " + toString((alignmentLength-filteredLength))); m->mothurOutEndLine();
@@ -251,10 +235,6 @@ int FilterSeqsCommand::execute() {
                for(int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();      }
                m->mothurOutEndLine();
                
-               #ifdef USE_MPI
-                       }
-               #endif
-
                return 0;
                
        }
@@ -291,8 +271,8 @@ string FilterSeqsCommand::createFilter() {
                        
 #ifdef USE_MPI 
                                int pid, rc, ierr; 
-                               char* buf;
                                int Atag = 1; int Ttag = 2; int Ctag = 3; int Gtag = 4; int Gaptag = 5;
+                               int tag = 2001;
                                
                                MPI_Status status; 
                                MPI_File in; 
@@ -300,38 +280,80 @@ string FilterSeqsCommand::createFilter() {
                                rc = MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
                                                
                                                        
-                               char* tempFileName = &(fastafileNames[s][0]);
+                               char* tempFileName = new char(fastafileNames[s].length());
+                               tempFileName = &(fastafileNames[s][0]);
+                               
                                MPI_File_open(MPI_COMM_WORLD, tempFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &in);  //comm, filename, mode, info, filepointer
-                                                               
+                               
                                if (pid == 0) { //you are the root process
                                                setLines(fastafileNames[s]);
                                                
                                                for (int j = 0; j < lines.size(); j++) { //each process
                                                        if (j != 0) { //don't send to yourself
-                                                               MPI_Send(&lines[j]->start, 1, MPI_INT, j, 2001, MPI_COMM_WORLD); //start position in file
-                                                               MPI_Send(&lines[j]->numSeqs, 1, MPI_INT, j, 2001, MPI_COMM_WORLD); //how many sequences we are sending
-                                                               MPI_Send(&bufferSizes[j], 1, MPI_INT, j, 2001, MPI_COMM_WORLD); //how bytes for the read
+                                                               MPI_Send(&lines[j]->start, 1, MPI_INT, j, tag, MPI_COMM_WORLD); //start position in file
+                                                               MPI_Send(&lines[j]->numSeqs, 1, MPI_INT, j, tag, MPI_COMM_WORLD); //how many sequences we are sending
+                                                               MPI_Send(&bufferSizes[j], 1, MPI_INT, j, tag, MPI_COMM_WORLD); //how bytes for the read
                                                        }
                                                }
-                                               cout << "done sending" << endl;
-                                               cout << "parent = " << pid << " lines = " << lines[pid]->start << '\t' << lines[pid]->numSeqs << " size = " <<  lines.size() << endl;   
-                                               
-                                               buf = new char(bufferSizes[0]);
-                       cout << pid << '\t' << bufferSizes[0] << " line 1 start pos = " << lines[1]->start   << " buffer size 0 " << bufferSizes[0] << " buffer size 1 " << bufferSizes[1] << endl;                     
+                                               //cout << "done sending" << endl;
+                                               //cout << "parent = " << pid << " lines = " << lines[pid]->start << '\t' << lines[pid]->numSeqs << " size = " <<  lines.size() << endl; 
+                                                
+                               cout << "parent =  " << pid << " address of Filter " << &F << " address of FilterString  " << &filterString << " address of numSeqs = " << &numSeqs << " address of soft = " << &soft << endl;          
+                               
+                                               char* buf = new char(bufferSizes[0]);
+                       //cout << pid << '\t' << bufferSizes[0] << " line 1 start pos = " << lines[1]->start   << " buffer size 0 " << bufferSizes[0] << " buffer size 1 " << bufferSizes[1] << endl;                   
                                                MPI_File_read_at(in, 0, buf, bufferSizes[0], MPI_CHAR, &status);
                                                
-               cout << pid << " done reading " << endl;
+               cout << pid << " done reading " << &buf <<  endl;
                                                string tempBuf = buf;
-                       cout << pid << '\t' << (tempBuf.substr(0, 10)) << endl;                                                                 
+                                               delete buf;
+                       //cout << pid << '\t' << (tempBuf.substr(0, 10)) << endl;
+                       
+                                               //parse buffer                                          
+                                               istringstream iss (tempBuf,istringstream::in);
+                                               string name, seqstring;
+                                               vector<string> seqs;
+                                       
+                                               while (iss) {
+                       
+                                                       if (m->control_pressed) { return filterString; }
+                                                       cout << "here" << endl;                 
+                                                       Sequence seq(iss); 
+                                                       cout << "here1" << endl;                        
+                                                       gobble(iss);
+                                                       cout << seq.getName() << endl;          
+                                                       if (seq.getName() != "") {
+                                                               seqs.push_back(seq.getAligned());       
+                                                       }
+                                                       
+                                               }
+                                               
+                                               for(int i=0;i<seqs.size();i++){
+                               
+                                                       if (m->control_pressed) { return filterString; }
+                       
+                                                       Sequence seq("", seqs[i]);
+                       
+                                                       if(trump != '*'){       F.doTrump(seq); }
+                                                       if(isTrue(vertical) || soft != 0){      F.getFreqs(seq);        }
+                                                       cout.flush();
+                                               
+                                                       //report progress
+                                                       if((i+1) % 100 == 0){   m->mothurOut(toString(i+1)); m->mothurOutEndLine();             }
+                                               }
+               
+                                               //report progress
+                                               if((seqs.size()) % 100 != 0){   m->mothurOut(toString(seqs.size())); m->mothurOutEndLine();             }
+
                                                //do your part
-                                               MPICreateFilter(F, tempBuf);
+                                               //MPICreateFilter(F, seqs);
                                                
-                                               vector<int> temp; temp.resize(numSeqs);
+                                               vector<int> temp; temp.resize(alignmentLength);
                                                
                                                //get the frequencies from the child processes
                                                for(int i = 0; i < ((processors-1)*5); i++) { 
                                cout << "i = " << i << endl;
-                                                       int ierr = MPI_Recv(&temp, numSeqs, MPI_INT, MPI_ANY_SOURCE, 2001, MPI_COMM_WORLD, &status); 
+                                                       int ierr = MPI_Recv(&temp, alignmentLength, MPI_INT, MPI_ANY_SOURCE, tag, MPI_COMM_WORLD, &status); 
                                                        
                                                        int receiveTag = temp[temp.size()-1];  //child process added a int to the end to indicate what letter count this is for
                                                        
@@ -355,33 +377,70 @@ string FilterSeqsCommand::createFilter() {
                                                
                                }else { //i am the child process
                                        int startPos, numLines, bufferSize;
-                               cout << "child = " << pid << endl;
-                                       ierr = MPI_Recv(&startPos, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
-                                       ierr = MPI_Recv(&numLines, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
-                                       ierr = MPI_Recv(&bufferSize, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
-                               cout << "child = " << pid << " done recv messages startpos = " << startPos << " numLines = " << numLines << " buffersize = " << bufferSize << endl;     
+                               cout << "child = " << pid << " address of Filter " << &F << " address of FilterString  " << &filterString << " address of numSeqs = " << &numSeqs << " address of soft = " << &soft<< endl;     
+                                       ierr = MPI_Recv(&startPos, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
+                                       ierr = MPI_Recv(&numLines, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
+                                       ierr = MPI_Recv(&bufferSize, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
+                               //cout << "child = " << pid << " done recv messages startpos = " << startPos << " numLines = " << numLines << " buffersize = " << bufferSize << endl;   
                                
                                        
                                        //send freqs
                                        char* buf2 = new char(bufferSize);
                                        MPI_File_read_at( in, startPos, buf2, bufferSize, MPI_CHAR, &status);
-                               cout << pid << " done reading " << endl;
+                               cout << pid << " done reading " << &buf2 <<  endl;
                                        
                                        string tempBuf = buf2;
-                       cout << pid << '\t' << (tempBuf.substr(0, 10)) << endl;
-                                       MPICreateFilter(F, tempBuf);
+                                       delete buf2;
+               //      cout << pid << '\t' << (tempBuf.substr(0, 10)) << endl;
+                                       istringstream iss (tempBuf,istringstream::in);
+                                       
+                                       string name, seqstring;
+                                       vector<string> seqs;
+                                       
+                                       while (iss) {
+                       
+                                               if (m->control_pressed) { return filterString; }
+                                               cout << "here" << endl;                 
+                                               Sequence seq(iss); 
+                                               cout << "here1" << endl;                        
+                                               gobble(iss);
+                                               cout << seq.getName() << endl;  
+                                                       
+                                               if (seq.getName() != "") {
+                                                       seqs.push_back(seq.getAligned());       
+                                               }
+                                       }
+
+                                       for(int i=0;i<seqs.size();i++){
+                               
+                                               if (m->control_pressed) { return filterString; }
+                       
+                                               Sequence seq("", seqs[i]);
+                       
+                                               if(trump != '*'){       F.doTrump(seq); }
+                                               if(isTrue(vertical) || soft != 0){      F.getFreqs(seq);        }
+                                               cout.flush();
+                                               
+                                               //report progress
+                                               if((i+1) % 100 == 0){   m->mothurOut(toString(i+1)); m->mothurOutEndLine();             }
+                                       }
+               
+                                       //report progress
+                                       if((seqs.size()) % 100 != 0){   m->mothurOut(toString(seqs.size())); m->mothurOutEndLine();             }
+               
+                                       //MPICreateFilter(F, seqs);
                                
                                        //send my fequency counts
                                        F.a.push_back(Atag);
-                                       int ierr = MPI_Send( &F.a[0], alignmentLength, MPI_INT, 0, 2001, MPI_COMM_WORLD);
+                                       int ierr = MPI_Send( &F.a[0], alignmentLength, MPI_INT, 0, tag, MPI_COMM_WORLD);
                                        F.t.push_back(Ttag);
-                                       ierr = MPI_Send( &F.t[0], alignmentLength, MPI_INT, 0, 2001, MPI_COMM_WORLD);
+                                       ierr = MPI_Send( &F.t[0], alignmentLength, MPI_INT, 0, tag, MPI_COMM_WORLD);
                                        F.c.push_back(Ctag);
-                                       ierr = MPI_Send( &F.c[0], alignmentLength, MPI_INT, 0, 2001, MPI_COMM_WORLD);
+                                       ierr = MPI_Send( &F.c[0], alignmentLength, MPI_INT, 0, tag, MPI_COMM_WORLD);
                                        F.g.push_back(Gtag);
-                                       ierr = MPI_Send( &F.g[0], alignmentLength, MPI_INT, 0, 2001, MPI_COMM_WORLD);
+                                       ierr = MPI_Send( &F.g[0], alignmentLength, MPI_INT, 0, tag, MPI_COMM_WORLD);
                                        F.gap.push_back(Gaptag);
-                                       ierr = MPI_Send( &F.gap[0], alignmentLength, MPI_INT, 0, 2001, MPI_COMM_WORLD);
+                                       ierr = MPI_Send( &F.gap[0], alignmentLength, MPI_INT, 0, tag, MPI_COMM_WORLD);
                                        
                                        cout << "child " << pid << " done sending counts" << endl;
                                }
@@ -484,12 +543,9 @@ int FilterSeqsCommand::driverCreateFilter(Filters& F, string filename, linePair*
        }
 }
 /**************************************************************************************/
-int FilterSeqsCommand::MPICreateFilter(Filters& F, string temp) {      
+int FilterSeqsCommand::MPICreateFilter(Filters& F, vector<string>& seqStrings) {       
        try {
                
-               vector<string> seqStrings;
-               parseBuffer(temp, seqStrings);
-               
                for(int i=0;i<seqStrings.size();i++){
                                
                        if (m->control_pressed) { return 1; }
@@ -610,18 +666,24 @@ int FilterSeqsCommand::parseBuffer(string file, vector<string>& seqs) {
                
                istringstream iss (file,istringstream::in);
                string name, seqstring;
-               
+int pid;
+MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
+       Sequence* seq34 = new Sequence();       
+cout << "address of new sequence " << pid << '\t' << seq34 << endl;
+cout << "address of seqStrings " << pid << '\t' << &seqs << endl;
+       
                while (iss) {
                        
                        if (m->control_pressed) { return 0; }
                cout << "here" << endl;                 
-                       Sequence seq(iss); 
+                       Sequence* seq = new Sequence(iss); 
        cout << "here1" << endl;                        
                        gobble(iss);
-       cout << seq.getName() << endl;          
-                       if (seq.getName() != "") {
-                               seqs.push_back(seq.getAligned());       
+       cout << seq->getName() << endl;         
+                       if (seq->getName() != "") {
+                               seqs.push_back(seq->getAligned());      
                        }
+                       delete seq;
                }
                
                return 0;
index 3cc007c059c63de5f28eee57ac0afcf78d00dc33..5eb49d3802177bf998e8fe9d0ba1dd80c2828709 100644 (file)
@@ -45,7 +45,7 @@ private:
        string createFilter();
        int createProcessesCreateFilter(Filters&, string);
        int driverCreateFilter(Filters&, string, linePair*);
-       int MPICreateFilter(Filters&, string);  
+       int MPICreateFilter(Filters&, vector<string>&); 
        int setLines(string);
        int parseBuffer(string, vector<string>&);
        
index 6631489a1f67fa5ba486108c0421d562a8953fa5..75d03e16d62a4c01b20236b42c00c1e00cd0bfc0 100644 (file)
@@ -43,8 +43,13 @@ int main(int argc, char *argv[]){
                time_t ltime = time(NULL); /* calendar time */  
                string logFileName = "mothur." + toString(ltime) + ".logfile";
                
+               #ifdef USE_MPI
+                       MPI_Init(&argc, &argv); 
+               #endif
+
                m->setFileName(logFileName);
                
+                               
                //version
                #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                        system("clear");
@@ -103,9 +108,8 @@ int main(int argc, char *argv[]){
                
                #ifdef USE_MPI
                        m->mothurOutJustToLog("Using MPI\n");
-                       MPI_Init(&argc, &argv); 
                #endif
-                               
+               
                //srand(54321);
                srand( (unsigned)time( NULL ) );
                
index 0f4faed55e30930b7cc2d7f7cc6f91b06e38ba6f..fe6fd26b09765e43b1032632564401ae86f36c6c 100644 (file)
@@ -20,7 +20,19 @@ MothurOut* MothurOut::getInstance() {
 void MothurOut::setFileName(string filename)  {
        try {
                logFileName = filename;
+               
+               #ifdef USE_MPI
+                       int pid;
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
+                                       
+                       if (pid == 0) { //only one process should output to screen
+               #endif
+               
                openOutputFile(filename, out);
+               
+               #ifdef USE_MPI
+                       }
+               #endif
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "setFileName");
@@ -31,7 +43,19 @@ void MothurOut::setFileName(string filename)  {
 MothurOut::~MothurOut() {
        try {
                _uniqueInstance = 0;
+               
+               #ifdef USE_MPI
+                       int pid;
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
+                                       
+                       if (pid == 0) { //only one process should output to screen
+               #endif
+               
                out.close();
+               
+               #ifdef USE_MPI
+                       }
+               #endif
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "MothurOut");
@@ -42,10 +66,20 @@ MothurOut::~MothurOut() {
 /*********************************************************************************************/
 void MothurOut::mothurOut(string output) {
        try {
-       
+               
+               #ifdef USE_MPI
+                       int pid;
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
+                                       
+                       if (pid == 0) { //only one process should output to screen
+               #endif
+               
                cout << output;
                out << output;
                
+               #ifdef USE_MPI
+                       }
+               #endif
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "MothurOut");
@@ -55,8 +89,19 @@ void MothurOut::mothurOut(string output) {
 /*********************************************************************************************/
 void MothurOut::mothurOutEndLine() {
        try {
+               #ifdef USE_MPI
+                       int pid;
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
+                                       
+                       if (pid == 0) { //only one process should output to screen
+               #endif
+               
                cout << endl;
                out << endl;
+               
+               #ifdef USE_MPI
+                       }
+               #endif
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "MothurOutEndLine");
@@ -66,7 +111,18 @@ void MothurOut::mothurOutEndLine() {
 /*********************************************************************************************/
 void MothurOut::mothurOutJustToLog(string output) {
        try {
+               #ifdef USE_MPI
+                       int pid;
+                       MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
+                                       
+                       if (pid == 0) { //only one process should output to screen
+               #endif
+               
                out << output;
+               
+               #ifdef USE_MPI
+                       }
+               #endif
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "MothurOutJustToLog");
index b73bfab7caefdb0a97e5f7cc8f3271ec3e51cb57..3bd80a87fde16f95d1bf1f8ae9369c0f962eb181 100644 (file)
@@ -44,13 +44,14 @@ Sequence::Sequence(istringstream& fastaString){
                initialize();
        cout << "after mothur initialize" << endl;
                fastaString >> name;
-       cout << "after name "  << endl;
+       cout << pid << " after name "  << name << endl;
                name = name.substr(1);
+
                string sequence;
-               
+cout << pid << " name = "  << name << endl;            
                //read comments
                while ((name[0] == '#') && fastaString) { 
-                       while (fastaString)     {       char c = fastaString.get(); if (c == 10 || c == 13){    break;  }       } // get rest of line if there's any crap there
+                       while (!fastaString.eof())      {       char c = fastaString.get(); if (c == 10 || c == 13){    break;  }       } // get rest of line if there's any crap there
                        sequence = getCommentString(fastaString);
                        
                        if (fastaString) {  
@@ -60,13 +61,13 @@ Sequence::Sequence(istringstream& fastaString){
                                name = "";
                                break;
                        }
+                       cout << pid << "in while comment" << endl;      
                }
-       cout << "after mothur comment" << endl; 
-               //read real sequence
-               while (fastaString)     {       char c = fastaString.get(); if (c == 10 || c == 13){    break;  }       } // get rest of line if there's any crap there
-       cout << "after mothur name" << endl;    
+       cout << pid << "after mothur comment" << endl;  
+               while (!fastaString.eof())      {       char c = fastaString.get(); cout << pid << " char = " << int(c) << endl; if (c == 10 || c == 13){       break;  }       } // get rest of line if there's any crap there
+       cout << pid << " after mothur name" << endl;    
                sequence = getSequenceString(fastaString);              
-       cout << "after mothur sequence" << endl;        
+       cout << pid << " after mothur sequence" << endl;        
                setAligned(sequence);   
                //setUnaligned removes any gap characters for us                                                
                setUnaligned(sequence);         
@@ -168,9 +169,11 @@ string Sequence::getSequenceString(istringstream& fastaFile) {
        try {
                char letter;
                string sequence = "";   
-               
-               while(fastaFile){
+int pid;
+MPI_Comm_rank(MPI_COMM_WORLD, &pid);           
+               while(!fastaFile.eof()){
                        letter= fastaFile.get();
+       cout << pid << '\t' << letter << endl;
                        if(letter == '>'){
                                fastaFile.putback(letter);
                                break;