110 重访问结构 |
当发送一个结构数组时,确定对于每一结构的大小MPI和C编译器有同样的值是很重要的。最可移植的方法是将MPI-UB添加到结构的结尾的定义中。
/* initialize types and displs with addresses of items */ MPI_Address( &cmdline.display, &displs[0] ); MPI_Address( &cmdline.maxiter, &displs[1] ); MPI_Address( &cmdline.xmin, &displs[2] ); MPI_Address( &cmdline.width, &displs[3] ); MPI_Address( &cmdline+1, &displs[4] ); types[0] = MPI_CHAR; types[1] = MPI_INT; types[2] = MPI_DOUBLE; types[3] = MPI_INT; types[4] = MPI_UB; for (i = 4; i >= 0; i--) displs[i] -= displs[0]; MPI_Type_struct( 5, blockcounts, displs, types, &cmdtype ); MPI_Type_commit( &cmdtype );
Copyright: NPACT |