在centos上安装MPI

2018-05-02  本文已影响0人  tingjieee_19e5

安装(centos 7.2)

至此可以在shell中使用mpicc,通过which mpicc可以查看到设置的路径。

mpi代码示例:

#include <mpi.h>
#include <stdio.h>
#include <math.h>
int main(int argc,char** argv)
{
    int myid,numproces;
    int namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&myid);
    MPI_Comm_size(MPI_COMM_WORLD,&numproces);
    MPI_Get_processor_name(processor_name,&namelen);
    fprintf(stdout,"hello world! Process %d of %d on %s\n",
            myid,numproces,processor_name);
    MPI_Finalize();

    return 0;
}

编译:

mpicc -o hello hello.c

运行:

mpirun -np 4 ./hello

输出:

hello world! Process 0 of 4 on node25
hello world! Process 1 of 4 on node25
hello world! Process 3 of 4 on node25
hello world! Process 2 of 4 on node25

上一篇 下一篇

猜你喜欢

热点阅读