+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "PhyloDiversityCommand", "execute");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int PhyloDiversityCommand::createProcesses(vector<int>& procIters, Tree* t, map< string, vector<float> >& div, map<string, vector<float> >& sumDiv, int numIters, int increment, vector<int>& randomLeaf, set<int>& numSampledList, ofstream& outCollect, ofstream& outSum){
+ try {
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ int process = 1;
+ int num = 0;
+ vector<int> processIDS;
+ map< string, vector<float> >::iterator itSum;
+
+ 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){
+ driver(t, div, sumDiv, procIters[process], increment, randomLeaf, numSampledList, outCollect, outSum, false);
+
+ string outTemp = outputDir + toString(getpid()) + ".sumDiv.temp";
+ ofstream out;
+ m->openOutputFile(outTemp, out);
+
+ //output the sumDIversity
+ for (itSum = sumDiv.begin(); itSum != sumDiv.end(); itSum++) {
+ out << itSum->first << '\t' << (itSum->second).size() << '\t';
+ for (int k = 0; k < (itSum->second).size(); k++) {
+ out << (itSum->second)[k] << '\t';
+ }
+ out << endl;
+ }
+
+ out.close();
+
+ exit(0);
+ }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
+ }
+
+ driver(t, div, sumDiv, procIters[0], increment, randomLeaf, numSampledList, outCollect, outSum, true);
+
+ //force parent to wait until all the processes are done
+ for (int i=0;i<(processors-1);i++) {
+ int temp = processIDS[i];
+ wait(&temp);
+ }
+
+ //get data created by processes
+ for (int i=0;i<(processors-1);i++) {
+
+ //input the sumDIversity
+ string inTemp = outputDir + toString(processIDS[i]) + ".sumDiv.temp";
+ ifstream in;
+ m->openInputFile(inTemp, in);
+
+ //output the sumDIversity
+ for (int j = 0; j < sumDiv.size(); j++) {
+ string group = "";
+ int size = 0;
+
+ in >> group >> size; m->gobble(in);
+
+ for (int k = 0; k < size; k++) {
+ float tempVal;
+ in >> tempVal;
+
+ sumDiv[group][k] += tempVal;
+ }
+ m->gobble(in);
+ }
+
+ in.close();
+ remove(inTemp.c_str());
+ }
+
+#endif
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "PhyloDiversityCommand", "createProcesses");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int PhyloDiversityCommand::driver(Tree* t, map< string, vector<float> >& div, map<string, vector<float> >& sumDiv, int numIters, int increment, vector<int>& randomLeaf, set<int>& numSampledList, ofstream& outCollect, ofstream& outSum, bool doSumCollect){
+ try {
+ int numLeafNodes = randomLeaf.size();
+
+ for (int l = 0; l < numIters; l++) {