centos中mpich的安装及使用
安装(腾讯云centos 6.5 64位)
-
yum list mpich* 查看有什么版本的mpich包,在此处有版本2的,所以装版本2的 yum install mpich2 mpich2-devel mpich2-doc which mpicc 发现找不到该命令 find / -name "mpich" 然后会找到mpich的目录,可能会有好几个,有bin的那个就是我们要找的目录 cd ~ vi .bashrc 在后面加上MPI_ROOT=/usr/lib64/mpich export PATH=$MPI_ROOT/bin:$PATH 这里的目录视具体情况而定 source .bashrc 使之生效
使用(新建文件hello.c)
#include <mpi.h>
#include <stdio.h>
#include <math.h>
int main(int argc,char* argv[])
{
int myid, numprocs;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);/* 初始化并行环境 */
MPI_Comm_rank(MPI_COMM_WORLD,&myid);/* 当前进程的ID号 */
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);/* 进程的总數 */
MPI_Get_processor_name(processor_name,&namelen);/* 当前处理器的名称 */
fprintf(stderr,"Hello World! Process %d of %d on %s
",
myid, numprocs, processor_name);
MPI_Finalize();/* 结束并行环境 */
return 0;
}
mpicc -o hello hello.c mpirun -np 4 ./hello
