X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=aligncommand.cpp;h=bcc59675d3b545f68197a3f56911a769ebe249bb;hb=fefd5ee1517abd3bc38b469cb2dffc85a1571c7e;hp=6b0ef5a8b661efd635ad918965a4bd047e2aef52;hpb=60928795782d8f8648ec373d6a96b53032a77429;p=mothur.git diff --git a/aligncommand.cpp b/aligncommand.cpp index 6b0ef5a..bcc5967 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -110,7 +110,7 @@ AlignCommand::AlignCommand(){ //********************************************************************************************************************** AlignCommand::AlignCommand(string option) { try { - abort = false; calledHelp = false; + abort = false; calledHelp = false; ReferenceDB* rdb = ReferenceDB::getInstance(); //allow user to run help @@ -860,12 +860,14 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s try { int num = 0; processIDS.resize(0); + bool recalc = false; + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int process = 1; //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 @@ -882,12 +884,48 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s exit(0); }else { - m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - exit(0); + m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + recalc = true; + break; } } + if (recalc) { + for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); + vector positions; + positions = m->divideFile(filename, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } + + num = 0; + processIDS.resize(0); + process = 1; + + while (process != processors) { + 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 + process++; + }else if (pid == 0){ + num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename); + + //pass numSeqs to parent + ofstream out; + string tempFile = alignFileName + toString(m->mothurGetpid(process)) + ".num.temp"; + m->openOutputFile(tempFile, out); + out << num << endl; + out.close(); + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } + } + } + //do my part num = driver(lines[0], alignFileName, reportFileName, accnosFName, filename);