X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=metastatscommand.cpp;h=4ad7f600232a37f0ccc15f8a69e719b6a9ff34c1;hb=HEAD;hp=de9e373194b30bc97a2afbeceb49b5303aa66de3;hpb=ffa535cf04326227080b02594616971a2c3a5195;p=mothur.git diff --git a/metastatscommand.cpp b/metastatscommand.cpp index de9e373..4ad7f60 100644 --- a/metastatscommand.cpp +++ b/metastatscommand.cpp @@ -256,15 +256,14 @@ int MetaStatsCommand::execute(){ else if (numGroups < 2) { m->mothurOut("Not enough sets, I need at least 2 valid sets. Unable to complete command."); m->mothurOutEndLine(); m->control_pressed = true; } if(processors != 1){ - int numPairs = namesOfGroupCombos.size(); - int numPairsPerProcessor = numPairs / processors; - - for (int i = 0; i < processors; i++) { - int startPos = i * numPairsPerProcessor; - if(i == processors - 1){ - numPairsPerProcessor = numPairs - i * numPairsPerProcessor; - } - lines.push_back(linePair(startPos, numPairsPerProcessor)); + int remainingPairs = namesOfGroupCombos.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, numPairs)); //startIndex, numPairs + startIndex = startIndex + numPairs; + remainingPairs = remainingPairs - numPairs; } } @@ -368,7 +367,7 @@ int MetaStatsCommand::process(vector& thisLookUp){ #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