Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / bsend1.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 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10 #include "mpitestconf.h"
11 #ifdef HAVE_STRING_H
12 #include <string.h>
13 #endif
14
15 /*
16  * This is a simple program that tests bsend.  It may be run as a single
17  * process to simplify debugging; in addition, bsend allows send-to-self
18  * programs.
19  */
20 int main(int argc, char *argv[])
21 {
22     MPI_Comm comm = MPI_COMM_WORLD;
23     int dest = 0, src = 0, tag = 1;
24     int s1, s2, s3;
25     char *buf, *bbuf;
26     char msg1[7], msg3[17];
27     double msg2[2];
28     char rmsg1[64], rmsg3[64];
29     double rmsg2[64];
30     int errs = 0, rank;
31     int bufsize, bsize;
32
33     MTest_Init(&argc, &argv);
34     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
35
36     /* According to the standard, we must use the PACK_SIZE length of each
37      * message in the computation of the message buffer size */
38     MPI_Pack_size(7, MPI_CHAR, comm, &s1);
39     MPI_Pack_size(2, MPI_DOUBLE, comm, &s2);
40     MPI_Pack_size(17, MPI_CHAR, comm, &s3);
41     bufsize = 3 * MPI_BSEND_OVERHEAD + s1 + s2 + s3;
42     buf = (char *) malloc(bufsize);
43     MPI_Buffer_attach(buf, bufsize);
44
45     strncpy(msg1, "012345", 7);
46     strncpy(msg3, "0123401234012341", 17);
47     msg2[0] = 1.23;
48     msg2[1] = 3.21;
49
50     if (rank == src) {
51         /* These message sizes are chosen to expose any alignment problems */
52         MPI_Bsend(msg1, 7, MPI_CHAR, dest, tag, comm);
53         MPI_Bsend(msg2, 2, MPI_DOUBLE, dest, tag, comm);
54         MPI_Bsend(msg3, 17, MPI_CHAR, dest, tag, comm);
55     }
56
57     if (rank == dest) {
58         MPI_Recv(rmsg1, 7, MPI_CHAR, src, tag, comm, MPI_STATUS_IGNORE);
59         MPI_Recv(rmsg2, 10, MPI_DOUBLE, src, tag, comm, MPI_STATUS_IGNORE);
60         MPI_Recv(rmsg3, 17, MPI_CHAR, src, tag, comm, MPI_STATUS_IGNORE);
61
62         if (strcmp(rmsg1, msg1) != 0) {
63             errs++;
64             fprintf(stderr, "message 1 (%s) should be %s\n", rmsg1, msg1);
65         }
66         if (rmsg2[0] != msg2[0] || rmsg2[1] != msg2[1]) {
67             errs++;
68             fprintf(stderr,
69                     "message 2 incorrect, values are (%f,%f) but should be (%f,%f)\n",
70                     rmsg2[0], rmsg2[1], msg2[0], msg2[1]);
71         }
72         if (strcmp(rmsg3, msg3) != 0) {
73             errs++;
74             fprintf(stderr, "message 3 (%s) should be %s\n", rmsg3, msg3);
75         }
76     }
77
78     /* We can't guarantee that messages arrive until the detach */
79     MPI_Buffer_detach(&bbuf, &bsize);
80
81     free(buf);
82
83     MTest_Finalize(errs);
84
85     MPI_Finalize();
86     return 0;
87 }