X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=unifracweightedcommand.cpp;h=fb365776a6adccb86b0c7f968de55333431e4c81;hb=60928795782d8f8648ec373d6a96b53032a77429;hp=4883c48741717c677641c6b48bf7fe4ada0245f1;hpb=37b23ba7d98eca13d02cde8d3b1ad08ac92fefb9;p=mothur.git diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index 4883c48..fb36577 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -699,14 +699,16 @@ int UnifracWeightedCommand::runRandomCalcs(Tree* thisTree, vector usersS lines.clear(); //breakdown work between processors - 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; } + //get scores for random trees @@ -776,7 +778,7 @@ int UnifracWeightedCommand::createProcesses(Tree* t, vector< vector > na //pass numSeqs to parent ofstream out; - string tempFile = outputDir + toString(getpid()) + ".weightedcommand.results.temp"; + string tempFile = outputDir + m->mothurGetpid(process) + ".weightedcommand.results.temp"; m->openOutputFile(tempFile, out); for (int i = lines[process].start; i < (lines[process].start + lines[process].num); i++) { out << scores[i][(scores[i].size()-1)] << '\t'; } out << endl; out.close();