-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitStuffC.c
54 lines (42 loc) · 2 KB
/
initStuffC.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
45
46
47
48
49
50
51
52
53
54
/** -*- fill-column:110 -*-
@file initStuffC.c
@author Mitch Richling <https://www.mitchr.me/>
@Copyright Copyright 1999 by Mitch Richling. All rights reserved.
@brief Demonstrate@EOL
@Keywords LAM MPICH MPI
@Std C89 MPI1
Illustrates a few details missing from the "hello world" program including error detection and
MPI program abort. The following functions illustrated:
MPI_Errhandler_set
MPI_Abort
MPI_Get_processor_name
Not all platforms allow console I/O on all MPI processes, so this program can fail on some
platforms.
*/
#include <stdio.h> /* I/O lib C89 */
#include <mpi.h> /* MPI Std MPI */
int main(int argc, char *argv[]) {
int rank, size, prNameLen, retV;
char prName[MPI_MAX_PROCESSOR_NAME];
char errStr[MPI_MAX_ERROR_STRING];
int errLen;
MPI_Init(&argc, &argv);
/* The startup error handler is MPI_ERRORS_ARE_FATAL. This will cause all errors to abort the MPI
application (all tasks are exited). To get return codes, use MPI_ERRORS_RETURN. */
MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("INFO(%d,%d): I am alive\n", rank, size);
if((retV=MPI_Get_processor_name(prName, &prNameLen)) != MPI_SUCCESS) {
if(retV == MPI_ERR_UNKNOWN) {
printf("ERROR(%d,%d): Unknown error getting processor name.\n", rank, size);
} else {
MPI_Error_string(retV, errStr, &errLen);
printf("ERROR(%d,%d): Getting processor name: (%d,%s,%d)\n", rank, size, retV, errStr, errLen);
} /* end if/else */
MPI_Abort(MPI_COMM_WORLD, retV);
} /* end if */
printf("INFO(%d,%d): This processor is named: %s\n", rank, size, prName);
MPI_Finalize();
return 0;
} /* end func main */