学期末プロジェクト
Grid Challenge in SACSIS 2005
MPI部分
1つのプロセスしかget_problem()を呼べないので、get_problem()を呼んだプロセス(rank0)は、
get_problem()で得た情報を他のPEに伝える必要がある。よってMPI_Bcast関数を用いて
すべてのPEにデータをブロードキャストする。
1つのPEはファイルの総数(100)をPE数で割った数だけのファイルについて実行する。
そしてそれぞれのPEが実行した結果をMPI_Reduce関数を用いて集約する。
そしてget_problem()を呼んだプロセス(rank0)がanswer_problem()を呼ぶ。
以下、MPI部分のプログラムを載せる。
/* MPI */
int rank; // rank of the process
int numprocs; // number of the PE
int num = 0; // total number of the object in PE
char *copy_key; // copy of the original_key
int copy_len; // length of the key
/* Initialize */
MPI_Init(&argc, &argv);
/* Get my rank */
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
/* Get a number of total PEs */
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
if(rank==0){
/* get problem */
if(get_problem(PP, PATH, &original_key, &w, &h)!=0){
perror("get_proglem");
exit(EXIT_FAILURE);
}
copy_len=strlen(original_key);
}
/* Distribution: length of key */
MPI_Bcast(& copy_len, 1, MPI_INT, 0, MPI_COMM_WORLD);
copy_key = (char *)malloc((copy_len+1)*sizeof(char));
if(rank==0) copy_key=(char *)original_key;
/* Distribution: key & width & height */
MPI_Bcast(copy_key, copy_len, MPI_CHAR, 0, MPI_COMM_WORLD);
MPI_Bcast(&w, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(&h, 1, MPI_INT, 0, MPI_COMM_WORLD);
for(i=rank; i< File_num; i+=numprocs){}
/* integration of the rusult */
MPI_Reduce(&num, &result, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
if(rank==0){
/* the answer is correct or not */
answer_problem(PP, original_key, result, file_coordinates, PATH);
}
MPI_Finalize();
戻る