Configuring MPI under VS2012
1, first download installation Mpich, for:
http://www.mpich.org/downloads/
The finished directory looks like this:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/DD/wKiom1TtXj7x7Al6AACAK0j7vrw081.jpg "style=" float: none; "title=" Image 1.png "alt=" Wkiom1ttxj7x7al6aacak0j7vrw081.jpg "/>
2. Open VS, create the following project
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/DA/wKioL1TtX0jQP-N1AAM6mMefsIk355.jpg "style=" float: none; "title=" Image 2.png "alt=" Wkiol1ttx0jqp-n1aam6mmefsik355.jpg "/>
3. Select Project Properties, add header files and library files
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/DD/wKiom1TtXj-gZZ9bAAJwvkn6L-Q047.jpg "style=" float: none; "title=" Image 3.png "alt=" Wkiom1ttxj-gzz9baajwvkn6l-q047.jpg "/>
4. Introduction of MPI header files and libraries
(1) Find "VC + + directions-" Include Directories ", plus MPICH2 include file path, for example:" D:\software\MPICH2\include "
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/DA/wKioL1TtX0nh-eezAASDiFwQIqI199.jpg "style=" float: none; "title=" Image 4.png "alt=" Wkiol1ttx0nh-eezaasdifwqiqi199.jpg "/>
(2) left or "VC + + directions-"Library directories", the last addition of this item the path to the MPICH2 lib file, such as "D:\software\MPICH2\lib"
5, because the VC IO Library and the MPI macro definition conflict, so the need to pre -defined a mpich_ Skip_mpicxx macros, which causes the compilation to skip the mpicxx definition. Add "Mpich_skip_mpicxx" to the following location.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/DD/wKiom1TtXj_CdzJnAAOFh3wnIzw805.jpg "style=" float: none; "title=" Image 5.png "alt=" Wkiom1ttxj_cdzjnaaofh3wnizw805.jpg "/>
6. Set the runtime as multithreaded
in the following location, select multi-threaded Debug (/MTD) "can be selected by the drop-down order.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/DA/wKioL1TtX0mAA95eAASh3HZPTSo752.jpg "style=" float: none; "title=" Image 6.png "alt=" Wkiol1ttx0maa95eaash3hzptso752.jpg "/>
7. Add a connection library
in the following location, add the Mpi.lib "
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/DD/wKiom1TtXkDRGYpwAAO4YseK4TE913.jpg "style=" float: none; "title=" Image 7.png "alt=" Wkiom1ttxkdrgypwaao4ysek4te913.jpg "/>
8, register MPI, make the system know it.
Open "Start" and locate the "MPICH2" folder as follows:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/DA/wKioL1TtX0rChXgvAACC6laESfU331.jpg "style=" float: none; "title=" Image 8.png "alt=" Wkiol1ttx0rchxgvaacc6laesfu331.jpg "/>
Select "wmpiregister.exe", as follows:
Enter the user name and password (the user name and password here are the user name and password when you lock the screen), click " Register ", when the following appears Password encrypted into the Register "then click" OK "can.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/DD/wKiom1TtXkDxzFzYAAF32MUrqQU637.jpg "style=" float: none; "title=" Image 9.png "alt=" Wkiom1ttxkdxzfzyaaf32murqqu637.jpg "/>
9. Running the program
(1) First compile the source program in VS, get the. exe file;
(2) Open "Start" and find"wmpiexec.exe" under "MPICH2"folder, as follows
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/DA/wKioL1TtX0qTeRm4AAFSa56tGyk346.jpg "style=" float: none; "title=" Image 10.png "alt=" Wkiol1ttx0qterm4aafsa56tgyk346.jpg "/>
Select the. exe file you just compiled , such as "D:\program\vs_code\MPI_01\Release\mpi_01.exe"
Set the number of threads "ofprocesses", for example:4
Click Execute "execute", in the following edit box will appear the results of the run, as follows:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/DD/wKiom1TtXkDQ0W83AAGqiCMHky4357.jpg "style=" float: none; "title=" Image 11.png "alt=" Wkiom1ttxkdq0w83aagqicmhky4357.jpg "/>
Test Source:
#include "mpi.h" #include <stdio.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); Mpi_comm_size (Mpi_comm_world, &numprocs); Mpi_get_processor_name (Processor_name, &namelen); printf ("Hello world! Process%d of%d on%s\n ", myID, Numprocs, processor_name); Mpi_finalize (); return 0; }
This article is from the "Technology: Change the World" blog, be sure to keep this source http://kenneth123.blog.51cto.com/3512478/1615168
Configuring MPI under VS2012