]> git.donarmstrong.com Git - mothur.git/blobdiff - chimeraperseuscommand.cpp
added rjsd calculator. improved work balance load between processors for paralellize...
[mothur.git] / chimeraperseuscommand.cpp
index 0547802198960198d9d2a063bc498e79f04bfe33..b8d70c1b4c623c5a433da7334219af49a87fac00 100644 (file)
@@ -1077,13 +1077,16 @@ int ChimeraPerseusCommand::createProcessesGroups(string outputFName, string accn
                
                //divide the groups between the processors
                vector<linePair> 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)