-/**************************************************************************************************/
-void Ccode::createProcessesClosest() {
- try {
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
- int process = 0;
- vector<int> processIDS;
-
- //loop through and create all the processes you want
- while (process != processors) {
- int pid = fork();
-
- if (pid > 0) {
- processIDS.push_back(pid);
- process++;
- }else if (pid == 0){
-
- mothurOut("Finding top matches for sequences " + toString(lines[process]->start) + " to " + toString(lines[process]->end)); mothurOutEndLine();
- closest = findClosest(lines[process]->start, lines[process]->end, numWanted);
- mothurOut("Done finding top matches for sequences " + toString(lines[process]->start) + " to " + toString(lines[process]->end)); mothurOutEndLine();
-
- //write out data to file so parent can read it
- ofstream out;
- string s = toString(getpid()) + ".temp";
- openOutputFile(s, out);
-
- //output pairs
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- for (int j = 0; j < closest[i].size(); j++) {
- closest[i][j].seq->printSequence(out);
- }
- }
- out << ">" << endl; //to stop sequence read
-
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- for (int j = 0; j < closest[i].size(); j++) {
- out << closest[i][j].dist << '\t';
- }
- out << endl;
- }
-
- out.close();
-
- exit(0);
- }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); }
- }
-
- //force parent to wait until all the processes are done
- for (int i=0;i<processors;i++) {
- int temp = processIDS[i];
- wait(&temp);
- }
-
- //get data created by processes
- for (int i=0;i<processors;i++) {
- ifstream in;
- string s = toString(processIDS[i]) + ".temp";
- openInputFile(s, in);
-
- vector< vector<Sequence*> > tempClosest; tempClosest.resize(querySeqs.size());
- //get pairs
- for (int k = lines[i]->start; k < lines[i]->end; k++) {
- vector<Sequence*> tempVector;
-
- for (int j = 0; j < numWanted; j++) {
-
- Sequence* temp = new Sequence(in);
- gobble(in);
-
- tempVector.push_back(temp);
- }
-
- tempClosest[k] = tempVector;
- }
-
- string junk;
- in >> junk; gobble(in); // to get ">"
-
- vector< vector<float> > dists; dists.resize(querySeqs.size());
-
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- dists[i].resize(closest[i].size());
- for (int j = 0; j < closest[i].size(); j++) {
- in >> dists[i][j];
- }
- gobble(in);
- }
-
- for (int i = lines[process]->start; i < lines[process]->end; i++) {
- for (int j = 0; j < closest[i].size(); j++) {
- closest[i][j].seq = tempClosest[i][j];
- closest[i][j].dist = dists[i][j];
- }
- }
-
- in.close();
- remove(s.c_str());
- }
-
-
-#else
- closest = findClosest(lines[0]->start, lines[0]->end, numWanted);
-#endif
-
- }
- catch(exception& e) {
- errorOut(e, "Ccode", "createProcessesClosest");
- exit(1);
- }
-}