X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=aligncommand.cpp;h=bcc59675d3b545f68197a3f56911a769ebe249bb;hp=3222f8c2d72a32bef9898eb71dd9d270056de0c3;hb=fefd5ee1517abd3bc38b469cb2dffc85a1571c7e;hpb=aca78ed4a47dff8672ea8fd93cef0dfbaf0f7495 diff --git a/aligncommand.cpp b/aligncommand.cpp index 3222f8c..bcc5967 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -110,7 +110,7 @@ AlignCommand::AlignCommand(){ //********************************************************************************************************************** AlignCommand::AlignCommand(string option) { try { - abort = false; calledHelp = false; + abort = false; calledHelp = false; ReferenceDB* rdb = ReferenceDB::getInstance(); //allow user to run help @@ -860,6 +860,8 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s try { int num = 0; processIDS.resize(0); + bool recalc = false; + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int process = 1; @@ -882,12 +884,48 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s 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); + m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + recalc = true; + break; } } + if (recalc) { + for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); + vector positions; + positions = m->divideFile(filename, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } + + num = 0; + processIDS.resize(0); + process = 1; + + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename); + + //pass numSeqs to parent + ofstream out; + string tempFile = alignFileName + toString(m->mothurGetpid(process)) + ".num.temp"; + m->openOutputFile(tempFile, out); + out << num << endl; + out.close(); + + 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); + } + } + } + //do my part num = driver(lines[0], alignFileName, reportFileName, accnosFName, filename);