1 /* -*- Mode: C++; c-basic-offset:4 ; -*- */
2 /*
3  *
4  *  (C) 2001 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 
8 #include "mpi.h"
9 
10 #include "mpitestconf.h"
11 #ifdef HAVE_IOSTREAM
12 // Not all C++ compilers have iostream instead of iostream.h
13 #include <iostream>
14 #ifdef HAVE_NAMESPACE_STD
15 // Those that do often need the std namespace; otherwise, a bare "cout"
16 // is likely to fail to compile
17 using namespace std;
18 #endif
19 #else
20 #include <iostream.h>
21 #endif
22 #include <stdio.h>
23 #include "mpitestcxx.h"
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
27 
main(int argc,char ** argv)28 int main( int argc, char **argv)
29 {
30     int    errs = 0;
31     void *v;
32     bool flag;
33     int  vval;
34     int  rank, size;
35 
36     MTest_Init();
37     size = MPI::COMM_WORLD.Get_size();
38     rank = MPI::COMM_WORLD.Get_rank();
39 
40     flag = MPI::COMM_WORLD.Get_attr( MPI::TAG_UB, &v );
41     if (!flag) {
42 	errs++;
43 	cout << "Could not get TAG_UB\n";
44     }
45     else {
46 	vval = *(int*)v;
47 	if (vval < 32767) {
48 	    errs++;
49 	    cout << "Got too-small value (" << vval <<
50 		") for TAG_UB\n";
51 	}
52     }
53 
54     flag = MPI::COMM_WORLD.Get_attr( MPI::HOST, &v );
55     if (!flag) {
56 	errs++;
57 	cout << "Could not get HOST\n";
58     }
59     else {
60 	vval = *(int*)v;
61 	if ((vval < 0 || vval >= size) && vval != MPI::PROC_NULL) {
62 	    errs++;
63 	    cout << "Got invalid value " << vval << " for HOST\n";
64 	}
65     }
66     flag = MPI::COMM_WORLD.Get_attr( MPI::IO, &v );
67     if (!flag) {
68 	errs++;
69 	cout << "Could not get IO\n";
70     }
71     else {
72 	vval = *(int*)v;
73 	if ((vval < 0 || vval >= size) && vval != MPI::ANY_SOURCE &&
74 		  vval != MPI::PROC_NULL) {
75 	    errs++;
76 	    cout << "Got invalid value " << vval << " for IO\n";
77 	}
78     }
79 
80     flag = MPI::COMM_WORLD.Get_attr( MPI::WTIME_IS_GLOBAL, &v );
81     if (flag) {
82 	/* Wtime need not be set */
83 	vval = *(int*)v;
84 	if (vval < 0 || vval > 1) {
85 	    errs++;
86 	    cout << "Invalid value for WTIME_IS_GLOBAL (got " << vval << ")\n";
87 	}
88     }
89 
90     flag = MPI::COMM_WORLD.Get_attr( MPI::APPNUM, &v );
91     /* appnum need not be set */
92     if (flag) {
93 	vval = *(int *)v;
94 	if (vval < 0) {
95 	    errs++;
96 	    cout << "MPI_APPNUM is defined as " << vval <<
97 		" but must be nonnegative\n";
98 	}
99     }
100 
101     flag = MPI::COMM_WORLD.Get_attr( MPI::UNIVERSE_SIZE, &v );
102     /* MPI_UNIVERSE_SIZE need not be set */
103     if (flag) {
104 	/* But if it is set, it must be at least the size of comm_world */
105 	vval = *(int *)v;
106 	if (vval < size) {
107 	    errs++;
108 	    cout << "MPI_UNIVERSE_SIZE = " << vval <<
109 		", less than comm world (" << size << ")\n";
110 	}
111     }
112 
113     flag = MPI::COMM_WORLD.Get_attr( MPI::LASTUSEDCODE, &v );
114     /* Last used code must be defined and >= MPI_ERR_LASTCODE */
115     if (flag) {
116 	vval = *(int*)v;
117 	if (vval < MPI_ERR_LASTCODE) {
118 	    errs++;
119 	    cout << "MPI_LASTUSEDCODE points to an integer (" << vval <<
120 		") smaller than MPI_ERR_LASTCODE (" <<
121 		MPI_ERR_LASTCODE << ")\n";
122 	}
123     }
124     else {
125 	errs++;
126 	cout << "MPI_LASTUSECODE is not defined\n";
127     }
128 
129     MTest_Finalize( errs );
130     MPI::Finalize( );
131 
132     return 0;
133 }
134