centos中mpich的安装及使用

安装(腾讯云centos 6.5 64位)

  • 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\n",myid,numprocs,processor_name);

    MPI_Finalize();/* 结束并行环境 */
    return 0;
}

mpicc -o hello hello.c
mpirun -np 4 ./hello

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native