+ }else{ //you are a child process
+ MPI_Bcast(&numFastaSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD); //get numSeqs
+ MPIPos.resize(numFastaSeqs+1);
+ MPI_Bcast(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //get file positions
+
+ //figure out how many sequences you have to align
+ numSeqsPerProcessor = numFastaSeqs / processors;
+ int startIndex = pid * numSeqsPerProcessor;
+ if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; }
+
+ //align your part
+ driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBad, outMPIBadAccnos, MPIPos, badSeqNames);
+
+ if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBad); MPI_File_close(&outMPIBadAccnos); return 0; }
+
+ //send bad list
+ int badSize = badSeqNames.size();
+ MPI_Send(&badSize, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
+
+ /*
+ set<string>::iterator it;
+ for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
+ string name = *it;
+ int length = name.length();
+ char* buf2 = new char[length];
+ memcpy(buf2, name.c_str(), length);
+
+ MPI_Send(&length, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
+ MPI_Send(buf2, length, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
+ }*/
+ }
+
+ //close files
+ MPI_File_close(&inMPI);
+ MPI_File_close(&outMPIGood);
+ MPI_File_close(&outMPIBad);
+ MPI_File_close(&outMPIBadAccnos);
+
+#else
+
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ if(processors == 1){
+ ifstream inFASTA;
+ openInputFile(fastafile, inFASTA);
+ numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+ inFASTA.close();
+
+ lines.push_back(new linePair(0, numFastaSeqs));
+
+ driver(lines[0], goodSeqFile, badSeqFile, badAccnosFile, fastafile, badSeqNames);
+
+ if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
+ }else{
+ vector<int> positions;
+ processIDS.resize(0);
+
+ ifstream inFASTA;
+ openInputFile(fastafile, inFASTA);
+
+ string input;
+ while(!inFASTA.eof()){
+ input = getline(inFASTA);
+ if (input.length() != 0) {
+ if(input[0] == '>'){ long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); }
+ }
+ }
+ inFASTA.close();
+
+ numFastaSeqs = positions.size();
+
+ int numSeqsPerProcessor = numFastaSeqs / processors;
+
+ for (int i = 0; i < processors; i++) {
+ long int startPos = positions[ i * numSeqsPerProcessor ];
+ if(i == processors - 1){
+ numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
+ }
+ lines.push_back(new linePair(startPos, numSeqsPerProcessor));
+ }
+
+ createProcesses(goodSeqFile, badSeqFile, badAccnosFile, fastafile, badSeqNames);
+
+ rename((goodSeqFile + toString(processIDS[0]) + ".temp").c_str(), goodSeqFile.c_str());
+ rename((badSeqFile + toString(processIDS[0]) + ".temp").c_str(), badSeqFile.c_str());
+ rename((badAccnosFile + toString(processIDS[0]) + ".temp").c_str(), badAccnosFile.c_str());
+
+ //append alignment and report files
+ for(int i=1;i<processors;i++){
+ appendFiles((goodSeqFile + toString(processIDS[i]) + ".temp"), goodSeqFile);
+ remove((goodSeqFile + toString(processIDS[i]) + ".temp").c_str());
+
+ appendFiles((badSeqFile + toString(processIDS[i]) + ".temp"), badSeqFile);
+ remove((badSeqFile + toString(processIDS[i]) + ".temp").c_str());
+
+ appendFiles((badAccnosFile + toString(processIDS[i]) + ".temp"), badAccnosFile);
+ remove((badAccnosFile + toString(processIDS[i]) + ".temp").c_str());
+ }
+
+ if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
+ //read badSeqs in because root process doesnt know what other "bad" seqs the children found
+ ifstream inBad;
+ int ableToOpen = openInputFile(badAccnosFile, inBad, "no error");
+
+ if (ableToOpen == 0) {
+ badSeqNames.clear();
+ string tempName;
+ while (!inBad.eof()) {
+ inBad >> tempName; gobble(inBad);
+ badSeqNames.insert(tempName);
+ }
+ inBad.close();