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 );
47 msg2[0] = 1.23; msg2[1] = 3.21;
50 /* These message sizes are chosen to expose any alignment problems */
51 MPI_Bsend( msg1, 7, MPI_CHAR, dest, tag, comm );
52 MPI_Bsend( msg2, 2, MPI_DOUBLE, dest, tag, comm );
53 MPI_Bsend( msg3, 17, MPI_CHAR, dest, tag, comm );
57 MPI_Recv( rmsg1, 7, MPI_CHAR, src, tag, comm, MPI_STATUS_IGNORE );
58 MPI_Recv( rmsg2, 10, MPI_DOUBLE, src, tag, comm, MPI_STATUS_IGNORE );
59 MPI_Recv( rmsg3, 17, MPI_CHAR, src, tag, comm, MPI_STATUS_IGNORE );
61 if (strcmp( rmsg1, msg1 ) != 0) {
63 fprintf( stderr, "message 1 (%s) should be %s\n", rmsg1, msg1 );
65 if (rmsg2[0] != msg2[0] || rmsg2[1] != msg2[1]) {
68 "message 2 incorrect, values are (%f,%f) but should be (%f,%f)\n",
69 rmsg2[0], rmsg2[1], msg2[0], msg2[1] );
71 if (strcmp( rmsg3, msg3 ) != 0) {
73 fprintf( stderr, "message 3 (%s) should be %s\n", rmsg3, msg3 );
77 /* We can't guarantee that messages arrive until the detach */
78 MPI_Buffer_detach( &bbuf, &bsize );
80 MTest_Finalize( errs );