Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Include directory is in source_dir, not in binary_dir.
[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 main(int argc, char *argv[]);
24 int parse_args(int argc, char **argv);
25
26 int main(int argc, char *argv[])
27 {
28     int errs = 0;
29     char buffer[BUF_SIZE];
30     int n, size;
31     double a,b;
32     int pos;
33
34     /* Initialize MPI */
35     MPI_Init(&argc, &argv);
36     parse_args(argc, argv);
37
38     pos = 0;
39     n   = 10;
40     a   = 1.1;
41     b   = 2.2;
42
43     MPI_Pack(&n, 1, MPI_INT, buffer, BUF_SIZE, &pos, MPI_COMM_WORLD);
44     MPI_Pack(&a, 1, MPI_DOUBLE, buffer, BUF_SIZE, &pos, MPI_COMM_WORLD);
45     MPI_Pack(&b, 1, MPI_DOUBLE, buffer, BUF_SIZE, &pos, MPI_COMM_WORLD);
46
47     size = pos;
48     pos  = 0;
49     n    = 0;
50     a    = 0;
51     b    = 0;
52
53     MPI_Unpack(buffer, size, &pos, &n, 1, MPI_INT, MPI_COMM_WORLD);
54     MPI_Unpack(buffer, size, &pos, &a, 1, MPI_DOUBLE, MPI_COMM_WORLD);
55     MPI_Unpack(buffer, size, &pos, &b, 1, MPI_DOUBLE, MPI_COMM_WORLD);
56     /* Check results */
57     if (n != 10) { 
58         errs++;
59         if (verbose) fprintf(stderr, "Wrong value for n; got %d expected %d\n", n, 10 );
60     }
61     if (a != 1.1) { 
62         errs++;
63         if (verbose) fprintf(stderr, "Wrong value for a; got %f expected %f\n", a, 1.1 );
64     }
65     if (b != 2.2) { 
66         errs++;
67         if (verbose) fprintf(stderr, "Wrong value for b; got %f expected %f\n", b, 2.2 );
68     }
69
70     /* print message and exit */
71     if (errs) {
72         fprintf(stderr, "Found %d errors\n", errs);
73     }
74     else {
75         printf(" No Errors\n");
76     }
77     MPI_Finalize();
78     return 0;
79 }
80
81 int parse_args(int argc, char **argv)
82 {
83     /*
84     int ret;
85
86     while ((ret = getopt(argc, argv, "v")) >= 0)
87     {
88         switch (ret) {
89             case 'v':
90                 verbose = 1;
91                 break;
92         }
93     }
94     */
95     if (argc > 1 && strcmp(argv[1], "-v") == 0)
96         verbose = 1;
97     return 0;
98 }