]> git.donarmstrong.com Git - mothur.git/blob - mothurout.cpp
added MPI to dist.seqs command
[mothur.git] / mothurout.cpp
1 /*
2  *  m->mothurOut.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 2/25/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "mothurout.h"
11
12 /******************************************************/
13 MothurOut* MothurOut::getInstance() {
14         if( _uniqueInstance == 0) {
15                 _uniqueInstance = new MothurOut();
16         }
17         return _uniqueInstance;
18 }
19 /*********************************************************************************************/
20 void MothurOut::setFileName(string filename)  {
21         try {
22                 logFileName = filename;
23                 
24                 #ifdef USE_MPI
25                         int pid;
26                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
27                                         
28                         if (pid == 0) { //only one process should output to screen
29                 #endif
30                 
31                 openOutputFile(filename, out);
32                 
33                 #ifdef USE_MPI
34                         }
35                 #endif
36         }
37         catch(exception& e) {
38                 errorOut(e, "MothurOut", "setFileName");
39                 exit(1);
40         }
41 }
42 /*********************************************************************************************/
43 MothurOut::~MothurOut() {
44         try {
45                 _uniqueInstance = 0;
46                 
47                 #ifdef USE_MPI
48                         int pid;
49                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
50                                         
51                         if (pid == 0) { //only one process should output to screen
52                 #endif
53                 
54                 out.close();
55                 
56                 #ifdef USE_MPI
57                         }
58                 #endif
59         }
60         catch(exception& e) {
61                 errorOut(e, "MothurOut", "MothurOut");
62                 exit(1);
63         }
64 }
65
66 /*********************************************************************************************/
67 void MothurOut::mothurOut(string output) {
68         try {
69                 
70                 #ifdef USE_MPI
71                         int pid;
72                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
73                                         
74                         if (pid == 0) { //only one process should output to screen
75                 #endif
76                 
77                 cout << output;
78                 out << output;
79                 
80                 #ifdef USE_MPI
81                         }
82                 #endif
83         }
84         catch(exception& e) {
85                 errorOut(e, "MothurOut", "MothurOut");
86                 exit(1);
87         }
88 }
89 /*********************************************************************************************/
90 void MothurOut::mothurOutEndLine() {
91         try {
92                 #ifdef USE_MPI
93                         int pid;
94                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
95                                         
96                         if (pid == 0) { //only one process should output to screen
97                 #endif
98                 
99                 cout << endl;
100                 out << endl;
101                 
102                 #ifdef USE_MPI
103                         }
104                 #endif
105         }
106         catch(exception& e) {
107                 errorOut(e, "MothurOut", "MothurOutEndLine");
108                 exit(1);
109         }
110 }
111 /*********************************************************************************************/
112 void MothurOut::mothurOutJustToLog(string output) {
113         try {
114                 #ifdef USE_MPI
115                         int pid;
116                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
117                                         
118                         if (pid == 0) { //only one process should output to screen
119                 #endif
120                 
121                 out << output;
122                 
123                 #ifdef USE_MPI
124                         }
125                 #endif
126         }
127         catch(exception& e) {
128                 errorOut(e, "MothurOut", "MothurOutJustToLog");
129                 exit(1);
130         }
131 }
132 /*********************************************************************************************/
133 void MothurOut::errorOut(exception& e, string object, string function) {
134         mothurOut("Error: ");
135         mothurOut(toString(e.what()));
136         mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry.");
137         mothurOutEndLine();
138 }
139 /*********************************************************************************************/
140
141
142
143
144