幾個首先:
在工程屬性的
1.附加包含目錄裡加上mpich sdk的include路徑,如
"E:\Program Files\MPICH\SDK\Include"
2.附加庫目錄裡加上mpich sdk的lib路徑,如
"E:\Program Files\MPICH\SDK\Lib"
3.調試|命令裡加上 MPIRun.exe,主要是為了方便運行調試
別忘了在命令參數上加上 "-np 4 $(TargetPath)"
4.在我的電腦屬性的環境變量增加mpich bin的執行路徑,如
"E:\PROGRA~1\MPICH\mpd\bin"
建一個空的控制台程序,配置好上面的,你就可以使用下面的代碼段了。
#include <mpi.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#pragma comment (lib, "mpichd.lib")
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);
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();
if (myid == 0)
{
printf("\nPress a key and exit.\n");
getch();
}
return 0;
}
#include <mpi.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>#pragma comment (lib, "mpichd.lib")
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);
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();
if (myid == 0)
{
printf("\nPress a key and exit.\n");getch();
}
return 0;
}