📄 bsend1.c
字号:
#include "mpi.h"#include <stdio.h>#include <stdlib.h>/* * This is a simple program that tests bsend. It may be run as a single * process to simplify debugging; in addition, bsend allows send-to-self * programs. */int main( int argc, char *argv[] ){ MPI_Comm comm = MPI_COMM_WORLD; int dest = 0, src = 0, tag = 1; char *buf, *bbuf; char msg1[7], msg3[17]; double msg2[2]; char rmsg1[64], rmsg3[64]; double rmsg2[64]; int errs = 0, rank; int bufsize, bsize; MPI_Init( &argc, &argv ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); bufsize = 3 * MPI_BSEND_OVERHEAD + 7 + 17 + 2*sizeof(double); buf = (char *)malloc( bufsize ); MPI_Buffer_attach( buf, bufsize ); strncpy( msg1, "012345", 7 ); strncpy( msg3, "0123401234012341", 17 ); msg2[0] = 1.23; msg2[1] = 3.21; if (rank == src) { /* These message sizes are chosen to expose any alignment problems */ MPI_Bsend( msg1, 7, MPI_CHAR, dest, tag, comm ); MPI_Bsend( msg2, 2, MPI_DOUBLE, dest, tag, comm ); MPI_Bsend( msg3, 17, MPI_CHAR, dest, tag, comm ); } if (rank == dest) { MPI_Recv( rmsg1, 7, MPI_CHAR, src, tag, comm, MPI_STATUS_IGNORE ); MPI_Recv( rmsg2, 10, MPI_DOUBLE, src, tag, comm, MPI_STATUS_IGNORE ); MPI_Recv( rmsg3, 17, MPI_CHAR, src, tag, comm, MPI_STATUS_IGNORE ); if (strcmp( rmsg1, msg1 ) != 0) { errs++; fprintf( stderr, "message 1 (%s) should be %s\n", rmsg1, msg1 ); } if (rmsg2[0] != msg2[0] || rmsg2[1] != msg2[1]) { errs++; fprintf( stderr, "message 2 incorrect, values are (%f,%f) but should be (%f,%f)\n", rmsg2[0], rmsg2[1], msg2[0], msg2[1] ); } if (strcmp( rmsg3, msg3 ) != 0) { errs++; fprintf( stderr, "message 3 (%s) should be %s\n", rmsg3, msg3 ); } } /* We can't guarantee that messages arrive until the detach */ MPI_Buffer_detach( &bbuf, &bsize ); MPI_Finalize(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -