]> git.donarmstrong.com Git - mothur.git/blobdiff - weighted.cpp
working of get.mimarkspackage and sra command
[mothur.git] / weighted.cpp
index b0d06fb0078e0201975e7738d1321e7932230253..35c2c6c868982048f3daed2a4acd5d47d7727a8a 100644 (file)
@@ -36,13 +36,14 @@ EstOutput Weighted::getValues(Tree* t, int p, string o) {
                        }
                }
                
-        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;
         }
         
         data = createProcesses(t, namesOfGroupCombos, ct);
@@ -67,7 +68,7 @@ EstOutput Weighted::createProcesses(Tree* t, vector< vector<string> > namesOfGro
                
                //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
@@ -78,7 +79,7 @@ EstOutput Weighted::createProcesses(Tree* t, vector< vector<string> > namesOfGro
                        
                                //pass numSeqs to parent
                                ofstream out;
-                               string tempFile = outputDir + toString(getpid()) + ".weighted.results.temp";
+                               string tempFile = outputDir + m->mothurGetpid(process) + ".weighted.results.temp";
                                m->openOutputFile(tempFile, out);
        
                                out << Myresults.size() << endl;