-
Notifications
You must be signed in to change notification settings - Fork 1
/
CpptrajStdio.cpp
155 lines (142 loc) · 3.95 KB
/
CpptrajStdio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <cstdio>
#include <cstdarg>
#ifdef MPI
# include "Parallel.h"
#endif
static bool worldsilent = false; // If true suppress all mprintf output.
static bool supressErrorMsg = false; // If true supress all mprinterr output.
// mflush()
/** Call flush on STDOUT only if this is the master thread */
void mflush() {
# ifdef MPI
if (!Parallel::World().Master()) return;
# endif
fflush(stdout);
}
/** Print message to STDOUT even if worldsilent */
void loudPrintf(const char* format, ...) {
# ifdef MPI
if (!Parallel::World().Master()) return;
# endif
va_list args;
va_start(args,format);
vfprintf(stdout,format,args);
va_end(args);
}
/** Print message to STDERR even if supressErrorMsg */
void loudPrinterr(const char *format, ...) {
# ifdef MPI
if (!Parallel::World().Master()) return;
# endif
va_list args;
va_start(args,format);
vfprintf(stderr,format,args);
va_end(args);
}
#ifdef PARALLEL_DEBUG_VERBOSE
// -----------------------------------------------------------------------------
/** Master prints message to STDOUT, others to mpidebugfile. */
void mprintf(const char*format, ...) {
va_list args;
va_start(args,format);
if (Parallel::World().Master()) {
vfprintf(stdout, format, args);
vfprintf(Parallel::mpidebugfile_, format, args);
} else
vfprintf(Parallel::mpidebugfile_, format, args);
va_end(args);
}
/** Master prints message to STDERR, others to mpidebugfile. */
void mprinterr(const char *format, ...) {
va_list args;
va_start(args,format);
if (Parallel::World().Master()) {
vfprintf(stderr,format,args);
vfprintf(Parallel::mpidebugfile_, format, args);
} else
vfprintf(Parallel::mpidebugfile_, format, args);
va_end(args);
}
// -----------------------------------------------------------------------------
#else
/** Print message to STDOUT only if this is the master thread */
void mprintf(const char *format, ...) {
if (worldsilent) return;
# ifdef MPI
if (!Parallel::World().Master()) return;
# endif
va_list args;
va_start(args,format);
vfprintf(stdout,format,args);
va_end(args);
}
/** Print message to STDERR only if this is the master thread */
void mprinterr(const char *format, ...) {
if (supressErrorMsg) return;
# ifdef MPI
if (!Parallel::World().Master()) return;
# endif
va_list args;
va_start(args,format);
vfprintf(stderr,format,args);
va_end(args);
}
#endif
// rprintf()
/** Print message to STDOUT for this worldrank */
void rprintf(const char *format, ...) {
va_list args;
if (worldsilent) return;
va_start(args, format);
# ifdef MPI
char buffer[1024];
int nc = sprintf(buffer, "[%i]\t", Parallel::World().Rank());
nc += vsprintf(buffer + nc, format, args);
fwrite(buffer, 1, nc, stdout);
# else
vfprintf(stdout,format,args);
# endif
va_end(args);
}
// rprinterr()
/** Print message to STDERR for this worldrank */
void rprinterr(const char *format, ...) {
va_list args;
if (supressErrorMsg) return;
va_start(args,format);
# ifdef MPI
char buffer[1024];
int nc = sprintf(buffer, "[%i]\t", Parallel::World().Rank());
nc += vsprintf(buffer + nc, format, args);
fwrite(buffer, 1, nc, stderr);
# else
vfprintf(stderr,format,args);
# endif
va_end(args);
}
void SetWorldSilent(bool silentIn) { worldsilent = silentIn; }
void SupressErrorMsg(bool supressIn) { supressErrorMsg = supressIn; }
// printerr()
/** Print error message along with calling routine. */
/*void printerr(const char *ROUTINE, const char *format, ...) {
va_list args;
va_start(args,format);
fprintf(stdout,"Error: ");
if (ROUTINE!=0)
fprintf(stdout, "%s: ",ROUTINE);
vfprintf(stdout,format,args);
va_end(args);
fprintf(stdout,"\n");
}*/
// printwar()
/** Print warning message along with calling routine. */
/*void printwar(const char *ROUTINE, const char *format, ...) {
va_list args;
va_start(args,format);
fprintf(stdout, "Warning: ");
if (ROUTINE!=0)
fprintf(stdout,"%s: ",ROUTINE);
vfprintf(stdout,format,args);
va_end(args);
fprintf(stdout,"\n");
}*/