]> git.donarmstrong.com Git - mothur.git/blobdiff - unweighted.cpp
added oligos class. added check orient parameter to trim.flows, sffinfo, fastq.info...
[mothur.git] / unweighted.cpp
index a845f9bc2fa54a5c27b0d74aed20929f1aeb756f..3f4d205a82413c393a8a811ad9f772f1138e3b46 100644 (file)
@@ -51,13 +51,14 @@ EstOutput Unweighted::getValues(Tree* t, int p, string o) {
                }
         
         lines.clear();
-        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);
@@ -84,7 +85,7 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector<string> > namesOfG
                
                //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
@@ -99,7 +100,7 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector<string> > namesOfG
                                
                                //pass numSeqs to parent
                                ofstream out;
-                               string tempFile = outputDir + toString(getpid()) + ".unweighted.results.temp";
+                               string tempFile = outputDir + m->mothurGetpid(process) + ".unweighted.results.temp";
                                m->openOutputFile(tempFile, out);
                                out << myresults.size() << endl;
                                for (int i = 0; i < myresults.size(); i++) {  out << myresults[i] << '\t';  } out << endl;
@@ -316,7 +317,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB, int p, st
      
         lines.clear();
         int numPairs = namesOfGroupCombos.size();
-        int numPairsPerProcessor = numPairs / processors;
+        int numPairsPerProcessor = ceil(numPairs / processors);
      
         for (int i = 0; i < processors; i++) {
             int startPos = i * numPairsPerProcessor;
@@ -346,7 +347,7 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector<string> > namesOfG
 
                //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
@@ -359,7 +360,7 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector<string> > namesOfG
                                
                                //pass numSeqs to parent
                                ofstream out;
-                               string tempFile = outputDir + toString(getpid()) + ".unweighted.results.temp";
+                               string tempFile = outputDir + m->mothurGetpid(process) + ".unweighted.results.temp";
                                m->openOutputFile(tempFile, out);
                                out << myresults.size() << endl;
                                for (int i = 0; i < myresults.size(); i++) {  out << myresults[i] << '\t';  } out << endl;