您的位置:首页 > 其它

并行计算MPI [ 简单例子 ]

2011-08-23 15:56 281 查看
#include "mpi.h"

#include <stdio.h>

#include <stdlib.h>

int main(int argc, char** argv)

{

MPI_Comm comm;

int np, myid;

char processor_name[MPI_MAX_PROCESSOR_NAME];

int nameLen;

MPI_Init(&argc, &argv);

MPI_Comm_dup(MPI_COMM_WORLD, &comm);

MPI_Comm_rank(comm, &myid);

MPI_Comm_size(comm, &np);

MPI_Get_processor_name(processor_name, &nameLen);

printf("Process %d is running on %d processed!\n", myid, np);

fprintf(stderr,"Process %d is alive on %s\n", myid, processor_name);

MPI_Comm_free(&comm);

MPI_Finalize();

return 0;

}

******************************************************************************

jshen@blade01:~/program/mpi> mpicc mpi.c -o mpi

jshen@blade01:~/program/mpi> mpirun -np 4 ./mpi

Process 0 is running on 4 processed!

Process 0 is alive on blade01.ssc

Process 3 is alive on blade01.ssc

Process 2 is alive on blade01.ssc

Process 1 is alive on blade01.ssc

Process 1 is running on 4 processed!

Process 2 is running on 4 processed!

Process 3 is running on 4 processed!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: