]> git.donarmstrong.com Git - mothur.git/blobdiff - metastatscommand.cpp
changed int to pid_t type in fork(). roughed in get.mimarkscommand.
[mothur.git] / metastatscommand.cpp
index de9e373194b30bc97a2afbeceb49b5303aa66de3..4ad7f600232a37f0ccc15f8a69e719b6a9ff34c1 100644 (file)
@@ -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<SharedRAbundVector*>& 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