X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parsimony.cpp;h=9ab193fa9bd6ffdbeaa77c71f1c454a0899ba093;hb=cac38e9e251998fa0b825d00189534534948d226;hp=b12ca1fe742240a4c80e96d0d82bcb2ef612fa18;hpb=ac663461b19ad1436a06aa63f97221d1ff105482;p=mothur.git diff --git a/parsimony.cpp b/parsimony.cpp index b12ca1f..9ab193f 100644 --- a/parsimony.cpp +++ b/parsimony.cpp @@ -56,13 +56,14 @@ EstOutput Parsimony::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); @@ -88,7 +89,7 @@ EstOutput Parsimony::createProcesses(Tree* t, vector< vector > namesOfGr //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 @@ -101,7 +102,7 @@ EstOutput Parsimony::createProcesses(Tree* t, vector< vector > namesOfGr //pass numSeqs to parent ofstream out; - string tempFile = outputDir + toString(getpid()) + ".pars.results.temp"; + string tempFile = outputDir + m->mothurGetpid(process) + ".pars.results.temp"; m->openOutputFile(tempFile, out); out << myresults.size() << endl; for (int i = 0; i < myresults.size(); i++) { out << myresults[i] << '\t'; } out << endl;