]> git.donarmstrong.com Git - mothur.git/blobdiff - unifracweightedcommand.cpp
added rjsd calculator. improved work balance load between processors for paralellize...
[mothur.git] / unifracweightedcommand.cpp
index 4883c48741717c677641c6b48bf7fe4ada0245f1..1c146ac4d1b1168093cc6df20a8d37a930e1d56b 100644 (file)
@@ -699,14 +699,16 @@ int UnifracWeightedCommand::runRandomCalcs(Tree* thisTree, vector<double> 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