-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpi-printf.c
48 lines (41 loc) · 919 Bytes
/
mpi-printf.c
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
#include "mpi-printf.h"
void MPI_fprintf(FILE *fp, char *fmt, ...)
{
#define BUFSIZE 128
int rank;
int tag=10, p,np;
va_list args;
char str[BUFSIZE];
MPI_Status status;
#ifdef SUN
va_start(args);
#else
va_start(args,fmt);
#endif
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &np);
if (rank==0) {
fprintf(fp,"(PE%3d): ",rank);
vfprintf(fp,fmt,args);
for (p=1; p<np; p++) {
MPI_Recv(str,BUFSIZE,MPI_CHAR,p,tag, MPI_COMM_WORLD, &status);
fprintf(fp,"(PE%3d): ",p);
fprintf(fp,"%s",str);
}
} else {
vsprintf(str,fmt,args);
MPI_Send(str,BUFSIZE,MPI_CHAR,0,tag,MPI_COMM_WORLD);
}
va_end(args);
}
void MPI_printf(char *fmt, ...)
{
va_list args;
#ifdef SUN
va_start(args);
#else
va_start(args,fmt);
#endif
MPI_fprintf(stdout,fmt,args);
va_end(args);
}