]> git.donarmstrong.com Git - mothur.git/blobdiff - mothur.cpp
added MPI to dist.seqs command
[mothur.git] / mothur.cpp
index ba058ba3fde6d2dd2d25458f88be358f1c7c0408..75d03e16d62a4c01b20236b42c00c1e00cd0bfc0 100644 (file)
 #include "globaldata.hpp"
 #include "mothurout.h"
 
+
 /**************************************************************************************************/
 
 GlobalData* GlobalData::_uniqueInstance = 0;
 CommandFactory* CommandFactory::_uniqueInstance = 0;
 MothurOut* MothurOut::_uniqueInstance = 0;
 
+/***********************************************************************/
+volatile int ctrlc_pressed = 0;
+void ctrlc_handler ( int sig ) {
+       MothurOut* m = MothurOut::getInstance();
+    ctrlc_pressed = 1;
+       m->control_pressed = ctrlc_pressed;
+       
+       if (m->executing) { //if mid command quit execution, else quit mothur
+               m->mothurOutEndLine(); m->mothurOut("quitting command...");  m->mothurOutEndLine();
+       }else{
+               m->mothurOut("quitting mothur");  m->mothurOutEndLine();
+               exit(1);
+       }
+}
+/***********************************************************************/
 int main(int argc, char *argv[]){
        MothurOut* m = MothurOut::getInstance();
        try {
                
-               //string log = "mothur.logFile";
-               //remove(log.c_str());
-               
+               signal(SIGINT, ctrlc_handler );
+                               
                time_t ltime = time(NULL); /* calendar time */  
                string logFileName = "mothur." + toString(ltime) + ".logfile";
                
+               #ifdef USE_MPI
+                       MPI_Init(&argc, &argv); 
+               #endif
+
                m->setFileName(logFileName);
                
+                               
                //version
                #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                        system("clear");
@@ -85,8 +105,11 @@ int main(int argc, char *argv[]){
                m->mothurOutEndLine();                  
                m->mothurOut("Type 'quit()' to exit program");
                m->mothurOutEndLine();  
-
-                               
+               
+               #ifdef USE_MPI
+                       m->mothurOutJustToLog("Using MPI\n");
+               #endif
+               
                //srand(54321);
                srand( (unsigned)time( NULL ) );
                
@@ -116,7 +139,7 @@ int main(int argc, char *argv[]){
                        mothur = new InteractEngine(argv[0]);   
                }
                
-               while(bail == 0)                {       bail = mothur->getInput();                      }
+               while(bail == 0)        {       bail = mothur->getInput();      }
                
                string outputDir = mothur->getOutputDir();
                string newlogFileName = outputDir + logFileName;
@@ -125,7 +148,11 @@ int main(int argc, char *argv[]){
                rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
                
                delete mothur;
-
+               
+               #ifdef USE_MPI
+                       MPI_Finalize();
+               #endif
+               
                return 0;
        }
        catch(exception& e) {