linux没有mpicc怎么编译mpi,在centos上安装MPI

安装(centos 7.2)

yum list mpich*,查看MPI可安装的版本,我是直接全部安装

sudo yum -y mpich*

由于安装之后找不到命令,所以需要设置环境变量

sudo find / -name "mpicc",应该可以查看到安装路径

vim ~/.bashrc

#在文件中添加,具体路径要根据系统和具体环境,以下是我的情况:

export PATH=$PATH:/usr/lib64/mpich/bin/

source .bashrc 生效环境变量设置

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

mpi代码示例:

#include

#include

#include

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值