Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / env / cmdline.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "mpi.h"
4
5 /* 
6    This is a test program to see if command line arguments are handled
7    well.  Note that MPI doesn't *require* anything here, so this is 
8    simply used to acess "quality of implementation"
9
10    run with arguments
11        a "b c" "d'e" 'f"g" h'
12  */
13 int main( int argc, char *argv[] )
14 {
15     int i, rank, toterr, err = 0;
16     static char *eargv[5];
17
18     eargv[1] = "a";
19     eargv[2] = "b c";
20     eargv[3] = "d'e";
21     eargv[4] = "f\"g\" h";
22
23     MPI_Init( &argc, &argv );
24     
25     for (i=1; i<=4; i++) {
26         if (!argv[i]) {
27             printf( "Argument %d is null!\n", i );
28             err++;
29         }
30     }
31     MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
32     if (toterr) {
33         MPI_Abort( 1, MPI_COMM_WORLD );
34         return 0;
35     }
36
37     /* a "b c" "d'e" 'f"g" h' */
38     for (i=1; i<=4; i++) {
39         if (strcmp( argv[i], eargv[i] ) != 0) {
40             err++;
41             printf( "Found %s but expected %s\n", argv[i], eargv[i] );
42         }
43     }
44     MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
45
46     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
47     if (rank == 0) {
48         if (toterr) printf( "Found %d errors\n", toterr );
49         else        printf( " No Errors\n" );
50     }
51     
52     MPI_Finalize();
53     return 0;
54 }