「Message Passing Interface」の版間の差分

削除された内容 追加された内容
Yamagu (会話 | 投稿記録)
Yamagu (会話 | 投稿記録)
→‎プログラムの例: コメントを日本語に翻訳
124行目:
<source lang="c">
/*
"Hello World" MPI Test Programテストプログラム
*/
#include <mpi.h>
141行目:
int i;
MPI_Status stat;
/* MPI programs start with MPI_Initで開始する; all ここ以降で全'N' processes exist thereafterプロセスが使える */
MPI_Init(&argc,&argv);
/* find out how big the SPMD world is環境の規模を取得する */
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
/* そしてこのプロセスのランク(番号)は */
/* and this processes' rank is */
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
 
/* この時点で全プログラムは同等に走っており、SPMDモデルの中でこれらを区別する場合には
/* At this point, all programs are running equivalently, the rank
ランクで見分ける。ただしランク0のプログラムは特別な処理をしていることもある。... */
distinguishes the roles of the programs in the SPMD model, with
rank 0 often used specially... */
if(myid == 0)
{
167 ⟶ 166行目:
else
{
/* receive from rank 0から受信: */
MPI_Recv(buff, BUFSIZE, MPI_CHAR, 0, TAG, MPI_COMM_WORLD, &stat);
sprintf(idstr, "Processor %d ", myid);
strncat(buff, idstr, BUFSIZE-1);
strncat(buff, "reporting for duty", BUFSIZE-1);
/* send to rank 0に送信: */
MPI_Send(buff, BUFSIZE, MPI_CHAR, 0, TAG, MPI_COMM_WORLD);
}
 
/* MPI FinalizeでMPIのプログラムは終了する; ここは弱い同期ポイント */
/* MPI programs end with MPI Finalize; this is a weak synchronization point */
MPI_Finalize();
return 0;