Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
for one reason or another, Win hates forward declarations of main ..
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / localpack.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 /* based on the pack.c test in the mpich suite.
7  */
8
9 #include "mpi.h"
10 #include <math.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include "mpitest.h"
14 #include "mpitestconf.h"
15 #ifdef HAVE_STRING_H
16 #include <string.h>
17 #endif
18
19 static int verbose = 0;
20
21 #define BUF_SIZE 16384
22
23 int parse_args(int argc, char **argv);
24
25 int main(int argc, char *argv[])
26 {
27     int errs = 0;
28     char buffer[BUF_SIZE];
29     int n, size;
30     double a,b;
31     int pos;
32
33     /* Initialize MPI */
34     MPI_Init(&argc, &argv);
35     parse_args(argc, argv);
36
37     pos = 0;
38     n   = 10;
39     a   = 1.1;
40     b   = 2.2;
41
42     MPI_Pack(&n, 1, MPI_INT, buffer, BUF_SIZE, &pos, MPI_COMM_WORLD);
43     MPI_Pack(&a, 1, MPI_DOUBLE, buffer, BUF_SIZE, &pos, MPI_COMM_WORLD);
44     MPI_Pack(&b, 1, MPI_DOUBLE, buffer, BUF_SIZE, &pos, MPI_COMM_WORLD);
45
46     size = pos;
47     pos  = 0;
48     n    = 0;
49     a    = 0;
50     b    = 0;
51
52     MPI_Unpack(buffer, size, &pos, &n, 1, MPI_INT, MPI_COMM_WORLD);
53     MPI_Unpack(buffer, size, &pos, &a, 1, MPI_DOUBLE, MPI_COMM_WORLD);
54     MPI_Unpack(buffer, size, &pos, &b, 1, MPI_DOUBLE, MPI_COMM_WORLD);
55     /* Check results */
56     if (n != 10) { 
57         errs++;
58         if (verbose) fprintf(stderr, "Wrong value for n; got %d expected %d\n", n, 10 );
59     }
60     if (a != 1.1) { 
61         errs++;
62         if (verbose) fprintf(stderr, "Wrong value for a; got %f expected %f\n", a, 1.1 );
63     }
64     if (b != 2.2) { 
65         errs++;
66         if (verbose) fprintf(stderr, "Wrong value for b; got %f expected %f\n", b, 2.2 );
67     }
68
69     /* print message and exit */
70     if (errs) {
71         fprintf(stderr, "Found %d errors\n", errs);
72     }
73     else {
74         printf(" No Errors\n");
75     }
76     MPI_Finalize();
77     return 0;
78 }
79
80 int parse_args(int argc, char **argv)
81 {
82     /*
83     int ret;
84
85     while ((ret = getopt(argc, argv, "v")) >= 0)
86     {
87         switch (ret) {
88             case 'v':
89                 verbose = 1;
90                 break;
91         }
92     }
93     */
94     if (argc > 1 && strcmp(argv[1], "-v") == 0)
95         verbose = 1;
96     return 0;
97 }