+ namesOfGroupCombos.push_back(groups);
+ }
+ }
+
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ if(processors == 1){
+ data = driver(t, namesOfGroupCombos, 0, namesOfGroupCombos.size(), true);
+ }else{
+ 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));
+ }
+
+ data = createProcesses(t, namesOfGroupCombos, true);
+
+ lines.clear();
+ }
+ #else
+ data = driver(t, namesOfGroupCombos, 0, namesOfGroupCombos.size(), true);
+ #endif
+
+ return data;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Unweighted", "getValues");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+
+EstOutput Unweighted::createProcesses(Tree* t, vector< vector<string> > namesOfGroupCombos, bool usingGroups) {
+ try {
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ int process = 1;
+ int num = 0;
+ vector<int> processIDS;
+
+ EstOutput results;
+
+ //loop through and create all the processes you want
+ while (process != processors) {
+ int 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
+ process++;
+ }else if (pid == 0){
+ EstOutput myresults;
+ myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, usingGroups);
+
+ if (m->control_pressed) { exit(0); }
+
+ //pass numSeqs to parent
+ ofstream out;
+ string tempFile = outputDir + toString(getpid()) + ".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;
+ out.close();
+
+ exit(0);
+ }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
+ }
+
+ results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, usingGroups);
+
+ //force parent to wait until all the processes are done
+ for (int i=0;i<(processors-1);i++) {
+ int temp = processIDS[i];
+ wait(&temp);
+ }
+
+ if (m->control_pressed) { return results; }
+
+ //get data created by processes
+ for (int i=0;i<(processors-1);i++) {
+ ifstream in;
+ string s = outputDir + toString(processIDS[i]) + ".unweighted.results.temp";
+ m->openInputFile(s, in);
+
+ //get quantiles
+ if (!in.eof()) {
+ int num;
+ in >> num; m->gobble(in);
+
+ if (m->control_pressed) { break; }
+
+ double w;
+ for (int j = 0; j < num; j++) {
+ in >> w;
+ results.push_back(w);
+ }
+ m->gobble(in);