X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=bellerophon.cpp;h=833cfb907d6d4bd2aed8acb3d8522932ac3b2e7d;hp=e33230ed8b9949550bf716cb82e4c7bf6a6353ae;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=2bbb7273d4bf5209f098c764551c6e072d60df36 diff --git a/bellerophon.cpp b/bellerophon.cpp index e33230e..833cfb9 100644 --- a/bellerophon.cpp +++ b/bellerophon.cpp @@ -75,7 +75,7 @@ Bellerophon::Bellerophon(string name, bool filterSeqs, bool c, int win, int inc } //*************************************************************************************************************** -int Bellerophon::print(ostream& out, ostream& outAcc) { +int Bellerophon::print(ostream& out, ostream& outAcc, string s) { try { int above1 = 0; @@ -130,9 +130,9 @@ int Bellerophon::print(ostream& out, ostream& outAcc) { } #ifdef USE_MPI //*************************************************************************************************************** -int Bellerophon::print(MPI_File& out, MPI_File& outAcc) { +int Bellerophon::print(MPI_File& out, MPI_File& outAcc, string s) { try { - + int pid; MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are @@ -148,17 +148,26 @@ int Bellerophon::print(MPI_File& out, MPI_File& outAcc) { if (m->control_pressed) { return numSeqs; } - outString += "Name\tScore\tLeft\tRight\n"; + outString = "Name\tScore\tLeft\tRight\n"; + MPI_Status status; + int olength = outString.length(); + char* buf5 = new char[olength]; + memcpy(buf5, outString.c_str(), olength); + + MPI_File_write_shared(out, buf5, olength, MPI_CHAR, &status); + + delete buf5; + //output prefenence structure to .chimeras file for (int i = 0; i < best.size(); i++) { if (m->control_pressed) { return numSeqs; } - outString += best[i].name + "\t" + toString(best[i].score) + "\t" + best[i].leftParent + "\t" + best[i].rightParent + "\n"; - + outString = best[i].name + "\t" + toString(best[i].score) + "\t" + best[i].leftParent + "\t" + best[i].rightParent + "\n"; + MPI_Status status; int length = outString.length(); - char* buf2 = new char[length]; + char* buf2 = new char[length]; memcpy(buf2, outString.c_str(), length); MPI_File_write_shared(out, buf2, length, MPI_CHAR, &status); @@ -168,12 +177,12 @@ int Bellerophon::print(MPI_File& out, MPI_File& outAcc) { //calc # of seqs with preference above 95%tile if (best[i].score >= cutoffScore) { above1++; - string outAccString; + string outAccString = ""; outAccString += best[i].name + "\n"; MPI_Status statusAcc; length = outAccString.length(); - char* buf = new char[length]; + char* buf = new char[length]; memcpy(buf, outAccString.c_str(), length); MPI_File_write_shared(outAcc, buf, length, MPI_CHAR, &statusAcc); @@ -237,7 +246,7 @@ int Bellerophon::getChimeras() { numSeqsPerProcessor = iters / processors; //each process hits this only once - int startPos = pid * numSeqsPerProcessor; + unsigned long long startPos = pid * numSeqsPerProcessor; if(pid == processors - 1){ numSeqsPerProcessor = iters - pid * numSeqsPerProcessor; } @@ -265,7 +274,7 @@ int Bellerophon::getChimeras() { MPI_Recv(&length, 1, MPI_INT, j, 2001, MPI_COMM_WORLD, &status); char* buf = new char[length]; - MPI_Recv(&buf, length, MPI_CHAR, j, 2001, MPI_COMM_WORLD, &status); + MPI_Recv(&buf[0], length, MPI_CHAR, j, 2001, MPI_COMM_WORLD, &status); string temp = buf; if (temp.length() > length) { temp = temp.substr(0, length); } @@ -284,14 +293,14 @@ int Bellerophon::getChimeras() { //played with this a bit, but it may be better to try user-defined datatypes with set string lengths?? vector MPIBestSend = getBestWindow(lines[0]); pref.clear(); - + //send your result to parent for (int i = 0; i < numSeqs; i++) { if (m->control_pressed) { return 0; } int bestLength = MPIBestSend[i].length(); - char* buf = new char[bestLength]; + char* buf = new char[bestLength]; memcpy(buf, MPIBestSend[i].c_str(), bestLength); MPI_Send(&bestLength, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD); @@ -301,11 +310,11 @@ int Bellerophon::getChimeras() { MPIBestSend.clear(); } - + MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else //divide breakpoints between processors - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) if(processors == 1){ lines.push_back(linePair(0, iters)); @@ -317,7 +326,7 @@ int Bellerophon::getChimeras() { int numSeqsPerProcessor = iters / processors; for (int i = 0; i < processors; i++) { - int startPos = i * numSeqsPerProcessor; + unsigned long long startPos = i * numSeqsPerProcessor; if(i == processors - 1){ numSeqsPerProcessor = iters - i * numSeqsPerProcessor; } @@ -347,7 +356,7 @@ int Bellerophon::getChimeras() { int Bellerophon::createProcesses(vector mid) { try { -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int process = 0; int exitCommand = 1; vector processIDS; @@ -364,7 +373,11 @@ int Bellerophon::createProcesses(vector mid) { string tempOut = outputDir + toString(getpid()) + ".temp"; writePrefs(tempOut, lines[process]); exit(0); - }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } } //force parent to wait until all the processes are done @@ -522,7 +535,6 @@ int Bellerophon::createSparseMatrix(int startSeq, int endSeq, SparseMatrix* spar int Bellerophon::generatePreferences(vector left, vector right, int mid){ try { - float dme = 0.0; SeqMap::iterator itR; SeqMap::iterator itL; @@ -656,7 +668,7 @@ int Bellerophon::writePrefs(string file, linePair tempLine) { try { ofstream outTemp; - openOutputFile(file, outTemp); + m->openOutputFile(file, outTemp); //lets you know what part of the pref matrix you are writing outTemp << tempLine.start << '\t' << tempLine.num << endl; @@ -665,7 +677,7 @@ int Bellerophon::writePrefs(string file, linePair tempLine) { for (int j = 0; j < numSeqs; j++) { - if (m->control_pressed) { outTemp.close(); remove(file.c_str()); return 0; } + if (m->control_pressed) { outTemp.close(); m->mothurRemove(file); return 0; } outTemp << pref[i][j].name << '\t' << pref[i][j].leftParent << '\t' << pref[i][j].rightParent << '\t'; outTemp << pref[i][j].score << '\t' << pref[i][j].closestLeft << '\t' << pref[i][j].closestRight << '\t' << pref[i][j].midpoint << endl; @@ -686,28 +698,28 @@ int Bellerophon::readPrefs(string file) { try { ifstream inTemp; - openInputFile(file, inTemp); + m->openInputFile(file, inTemp); int start, num; //lets you know what part of the pref matrix you are writing - inTemp >> start >> num; gobble(inTemp); + inTemp >> start >> num; m->gobble(inTemp); for (int i = start; i < num; i++) { for (int j = 0; j < numSeqs; j++) { - if (m->control_pressed) { inTemp.close(); remove(file.c_str()); return 0; } + if (m->control_pressed) { inTemp.close(); m->mothurRemove(file); return 0; } inTemp >> pref[i][j].name >> pref[i][j].leftParent >> pref[i][j].rightParent; inTemp >> pref[i][j].score >> pref[i][j].closestLeft >> pref[i][j].closestRight >> pref[i][j].midpoint; - gobble(inTemp); + m->gobble(inTemp); } } inTemp.close(); - remove(file.c_str()); + m->mothurRemove(file); return 0; }