Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / mpich3-test / attr / baseattrcomm.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2001 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include <stdio.h>
8 #include "mpi.h"
9 #include "mpitest.h"
10
11 int main( int argc, char **argv)
12 {
13     int    errs = 0;
14     void *v;
15     int  flag;
16     int  vval;
17     int  rank, size;
18
19     MTest_Init( &argc, &argv );
20     MPI_Comm_size( MPI_COMM_WORLD, &size );
21     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
22
23     MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_TAG_UB, &v, &flag );
24     if (!flag) {
25         errs++;
26         fprintf( stderr, "Could not get TAG_UB\n" );
27     }
28     else {
29         vval = *(int*)v;
30         if (vval < 32767) {
31             errs++;
32             fprintf( stderr, "Got too-small value (%d) for TAG_UB\n", vval );
33         }
34     }
35
36     MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_HOST, &v, &flag );
37     if (!flag) {
38         errs++;
39         fprintf( stderr, "Could not get HOST\n" );
40     }
41     else {
42         vval = *(int*)v;
43         if ((vval < 0 || vval >= size) && vval != MPI_PROC_NULL) {
44             errs++;
45             fprintf( stderr, "Got invalid value %d for HOST\n", vval );
46         }
47     }
48     MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_IO, &v, &flag );
49     if (!flag) {
50         errs++;
51         fprintf( stderr, "Could not get IO\n" );
52     }
53     else {
54         vval = *(int*)v;
55         if ((vval < 0 || vval >= size) && vval != MPI_ANY_SOURCE &&
56                   vval != MPI_PROC_NULL) {
57             errs++;
58             fprintf( stderr, "Got invalid value %d for IO\n", vval );
59         }
60     }
61
62     MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_WTIME_IS_GLOBAL, &v, &flag );
63     if (flag) {
64         /* Wtime need not be set */
65         vval = *(int*)v;
66         if (vval < 0 || vval > 1) {
67             errs++;
68             fprintf( stderr, "Invalid value for WTIME_IS_GLOBAL (got %d)\n", 
69                      vval );
70         }
71     }
72
73     /* MPI 2.0, section 5.5.3 - MPI_APPNUM should be set if the program is
74        started with more than one executable name (e.g., in MPMD instead
75        of SPMD mode).  This is independent of the dynamic process routines,
76        and should be supported even if MPI_COMM_SPAWN and friends are not. */
77     MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_APPNUM, &v, &flag );
78     /* appnum need not be set */
79     if (flag) {
80         vval = *(int *)v;
81         if (vval < 0) {
82             errs++;
83             fprintf( stderr, "MPI_APPNUM is defined as %d but must be nonnegative\n", vval );
84         }
85     }
86
87     /* MPI 2.0 section 5.5.1.  MPI_UNIVERSE_SIZE need not be set, but
88        should be present.  */
89     MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &v, &flag );
90     /* MPI_UNIVERSE_SIZE need not be set */
91     if (flag) {
92         /* But if it is set, it must be at least the size of comm_world */
93         vval = *(int *)v;
94         if (vval < size) {
95             errs++;
96             fprintf( stderr, "MPI_UNIVERSE_SIZE = %d, less than comm world (%d)\n", vval, size );
97         }
98     }
99     
100     MPI_Comm_get_attr( MPI_COMM_WORLD, MPI_LASTUSEDCODE, &v, &flag );
101     /* Last used code must be defined and >= MPI_ERR_LASTCODE */
102     if (flag) {
103         vval = *(int*)v;
104         if (vval < MPI_ERR_LASTCODE) {
105             errs++;
106             fprintf( stderr, "MPI_LASTUSEDCODE points to an integer (%d) smaller than MPI_ERR_LASTCODE (%d)\n", vval, MPI_ERR_LASTCODE );
107         }
108     }
109     else {
110         errs++;
111         fprintf( stderr, "MPI_LASTUSECODE is not defined\n" );
112     }
113
114     MTest_Finalize( errs );
115     MPI_Finalize( );
116     
117     return 0;
118 }