1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
10 #include "mpitestconf.h"
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
20 int main(int argc, char *argv[])
22 MPI_Comm comm = MPI_COMM_WORLD;
23 int dest = 0, src = 0, tag = 1;
26 char msg1[7], msg3[17];
28 char rmsg1[64], rmsg3[64];
33 MTest_Init(&argc, &argv);
34 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
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);
45 strncpy(msg1, "012345", 7);
46 strncpy(msg3, "0123401234012341", 17);
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);
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);
62 if (strcmp(rmsg1, msg1) != 0) {
64 fprintf(stderr, "message 1 (%s) should be %s\n", rmsg1, msg1);
66 if (rmsg2[0] != msg2[0] || rmsg2[1] != msg2[1]) {
69 "message 2 incorrect, values are (%f,%f) but should be (%f,%f)\n",
70 rmsg2[0], rmsg2[1], msg2[0], msg2[1]);
72 if (strcmp(rmsg3, msg3) != 0) {
74 fprintf(stderr, "message 3 (%s) should be %s\n", rmsg3, msg3);
78 /* We can't guarantee that messages arrive until the detach */
79 MPI_Buffer_detach(&bbuf, &bsize);