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