- int *buf, bufsize, bsize;
-
- bufsize = 4 * (MSG_SIZE * sizeof(int) + MPI_BSEND_OVERHEAD);
- buf = (int *)malloc( bufsize );
- if (!buf) {
- fprintf( stderr, "Could not allocate buffer of %d bytes\n",
- bufsize );
- MPI_Abort( MPI_COMM_WORLD, 1 );
- }
- MPI_Buffer_attach( buf, bufsize );
-
- /* Initialize data */
- for (i=0; i<MSG_SIZE; i++) {
- b1[i] = i;
- b2[i] = MSG_SIZE + i;
- b3[i] = 2 * MSG_SIZE + i;
- b4[i] = 3 * MSG_SIZE + i;
- }
- /* Send and reset buffers after bsend returns */
- MPI_Bsend( b1, MSG_SIZE, MPI_INT, dest, 0, comm );
- for (i=0; i<MSG_SIZE; i++) b1[i] = -b1[i];
- MPI_Bsend( b2, MSG_SIZE, MPI_INT, dest, 1, comm );
- for (i=0; i<MSG_SIZE; i++) b2[i] = -b2[i];
- MPI_Bsend( b3, MSG_SIZE, MPI_INT, dest, 2, comm );
- for (i=0; i<MSG_SIZE; i++) b3[i] = -b3[i];
- MPI_Bsend( b4, MSG_SIZE, MPI_INT, dest, 3, comm );
- for (i=0; i<MSG_SIZE; i++) b4[i] = -b4[i];
-
- MPI_Barrier( comm );
- /* Detach waits until all messages received */
- MPI_Buffer_detach( &buf, &bsize );
+ int *buf, bufsize, bsize;
+
+ bufsize = 4 * (MSG_SIZE * sizeof(int) + MPI_BSEND_OVERHEAD);
+ buf = (int *) malloc(bufsize);
+ if (!buf) {
+ fprintf(stderr, "Could not allocate buffer of %d bytes\n", bufsize);
+ MPI_Abort(MPI_COMM_WORLD, 1);
+ }
+ MPI_Buffer_attach(buf, bufsize);
+
+ /* Initialize data */
+ for (i = 0; i < MSG_SIZE; i++) {
+ b1[i] = i;
+ b2[i] = MSG_SIZE + i;
+ b3[i] = 2 * MSG_SIZE + i;
+ b4[i] = 3 * MSG_SIZE + i;
+ }
+ /* Send and reset buffers after bsend returns */
+ MPI_Bsend(b1, MSG_SIZE, MPI_INT, dest, 0, comm);
+ for (i = 0; i < MSG_SIZE; i++)
+ b1[i] = -b1[i];
+ MPI_Bsend(b2, MSG_SIZE, MPI_INT, dest, 1, comm);
+ for (i = 0; i < MSG_SIZE; i++)
+ b2[i] = -b2[i];
+ MPI_Bsend(b3, MSG_SIZE, MPI_INT, dest, 2, comm);
+ for (i = 0; i < MSG_SIZE; i++)
+ b3[i] = -b3[i];
+ MPI_Bsend(b4, MSG_SIZE, MPI_INT, dest, 3, comm);
+ for (i = 0; i < MSG_SIZE; i++)
+ b4[i] = -b4[i];
+
+ MPI_Barrier(comm);
+ /* Detach waits until all messages received */
+ MPI_Buffer_detach(&buf, &bsize);
+ free(buf);