Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[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)
60             fprintf(stderr, "Wrong value for n; got %d expected %d\n", n, 10);
61     }
62     if (a != 1.1) {
63         errs++;
64         if (verbose)
65             fprintf(stderr, "Wrong value for a; got %f expected %f\n", a, 1.1);
66     }
67     if (b != 2.2) {
68         errs++;
69         if (verbose)
70             fprintf(stderr, "Wrong value for b; got %f expected %f\n", b, 2.2);
71     }
72
73     /* print message and exit */
74     if (errs) {
75         fprintf(stderr, "Found %d errors\n", errs);
76     }
77     else {
78         printf(" No Errors\n");
79     }
80     MPI_Finalize();
81     return 0;
82 }
83
84 int parse_args(int argc, char **argv)
85 {
86     /*
87      * int ret;
88      *
89      * while ((ret = getopt(argc, argv, "v")) >= 0)
90      * {
91      * switch (ret) {
92      * case 'v':
93      * verbose = 1;
94      * break;
95      * }
96      * }
97      */
98     if (argc > 1 && strcmp(argv[1], "-v") == 0)
99         verbose = 1;
100     return 0;
101 }