1. mpi简介
2. hello world
3. 计算矩阵和
4. 参考资料
1. mpi简介
mpi=(Message Passing Interface)目前一种比较著名的应用于并行环境的消息传递标准。mpich为实现mpi接口开源框架。
2. hello world
#include "mpi.h"
#include <iostream>
int main(int argc, char* argv[])
{
int rank;
int size;
MPI_Init(0,0);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
std::cout<<"Hello world from process "<<rank<<" of "<<size<<std::endl;
MPI_Finalize();
return 0;
}
编译: mpicxx -o test_mpi test_mpi.cpp
执行:mpirun -n 2 ./test_mpi
3. 计算矩阵和
#include "mpi.h"
#include <iostream>
#include <fstream>
int main(int argc, char* argv[])
{
using namespace std;
int rank;
int size;
MPI_Status Status;
MPI_Init(&argc, &argv);
MPI_Comm_ran