From: Sarah Westcott Date: Wed, 9 Apr 2014 13:18:00 +0000 (-0400) Subject: pre.cluster unable to spawn necessary processes adjustment. X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=63befd5322a476436f08d9ae24954f06fa191395 pre.cluster unable to spawn necessary processes adjustment. --- diff --git a/preclustercommand.cpp b/preclustercommand.cpp index def5325..10ed825 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -363,7 +363,8 @@ int PreClusterCommand::createProcessesGroups(string newFName, string newNName, s vector processIDS; int process = 1; int num = 0; - + bool recalc = false; + //sanity check if (groups.size() < processors) { processors = groups.size(); } @@ -401,12 +402,57 @@ int PreClusterCommand::createProcessesGroups(string newFName, string newNName, s outTemp.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); + }else { + 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) { + lines.clear(); + num = 0; + processIDS.resize(0); + process = 1; + + int remainingPairs = groups.size(); + int startIndex = 0; + for (int remainingProcessors = processors; remainingProcessors > 0; remainingProcessors--) { + int numPairs = remainingPairs; //case for last processor + if (remainingProcessors != 1) { numPairs = ceil(remainingPairs / remainingProcessors); } + lines.push_back(linePair(startIndex, (startIndex+numPairs))); //startIndex, endIndex + startIndex = startIndex + numPairs; + remainingPairs = remainingPairs - numPairs; + } + + 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){ + outputNames.clear(); + num = driverGroups(newFName + m->mothurGetpid(process) + ".temp", newNName + m->mothurGetpid(process) + ".temp", newMFile, lines[process].start, lines[process].end, groups); + + string tempFile = m->mothurGetpid(process) + ".outputNames.temp"; + ofstream outTemp; + m->openOutputFile(tempFile, outTemp); + + outTemp << outputNames.size(); + for (int i = 0; i < outputNames.size(); i++) { outTemp << outputNames[i] << endl; } + outTemp.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 = driverGroups(newFName, newNName, newMFile, lines[0].start, lines[0].end, groups);