X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=shhhseqscommand.cpp;h=f6fd90da276951724132140828d27c9de3a0d47a;hb=cac38e9e251998fa0b825d00189534534948d226;hp=82d956189a6f025fd57dc7e901e585456f59f8ab;hpb=c85db0a4be3a1f8037a71a23ca73f9762184e28a;p=mothur.git diff --git a/shhhseqscommand.cpp b/shhhseqscommand.cpp index 82d9561..f6fd90d 100644 --- a/shhhseqscommand.cpp +++ b/shhhseqscommand.cpp @@ -377,29 +377,32 @@ vector ShhhSeqsCommand::createProcessesGroups(SequenceParser& parser, st //divide the groups between the processors vector lines; - int numGroupsPerProcessor = groups.size() / processors; - for (int i = 0; i < processors; i++) { - int startIndex = i * numGroupsPerProcessor; - int endIndex = (i+1) * numGroupsPerProcessor; - if(i == (processors - 1)){ endIndex = groups.size(); } - lines.push_back(linePair(startIndex, endIndex)); - } + 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; + } + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) //loop through and create all the processes you want while (process != processors) { - int pid = fork(); + 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){ - mapfileNames = driverGroups(parser, newFName + toString(getpid()) + ".temp", newNName + toString(getpid()) + ".temp", newMName, lines[process].start, lines[process].end, groups); + mapfileNames = driverGroups(parser, newFName + m->mothurGetpid(process) + ".temp", newNName + m->mothurGetpid(process) + ".temp", newMName, lines[process].start, lines[process].end, groups); //pass filenames to parent ofstream out; - string tempFile = newMName + toString(getpid()) + ".temp"; + string tempFile = newMName + m->mothurGetpid(process) + ".temp"; m->openOutputFile(tempFile, out); out << mapfileNames.size() << endl; for (int i = 0; i < mapfileNames.size(); i++) {