通过如下cmd命令可完成修改:
REM 永久修改环境变量
wmic ENVIRONMENT where "name='include' and username='<system>'" set VariableValue='%include%;c:\Program Files\MPICH2\include'
wmic ENVIRONMENT where "name='lib' and username='<system>'" set VariableValue='%lib%;c:\Program Files\MPICH2\lib'
wmic ENVIRONMENT where "name='path' and username='<system>'" set VariableValue='%path%;c:\Program Files\MPICH2\bin'
REM 临时修改,即时生效
set include='%include%;c:\Program Files\MPICH2\include'
set lib='%lib%;c:\Program Files\MPICH2\lib'
set path='%path%;c:\Program Files\MPICH2\bin'
也通过: 右击我的电脑》属性》高级系统设置》环境变量 修改
3.命令行下编译执行并行程序 以mpich 自带程序为例, mpich/exampie/icpi.c
cl /c /o2 icpi.c
link /LIBPATH:"d:/Program Files/MPICH2/lib" icpi.obj mpi.lib
del *.obj
mpiexec.exe -n 2 icpi.exe
mpiexec.exe 运行出现
Aborting: unable to connect to ****, smpd version mismatch
无法使用mpiexec,是装MATLAB后,环境变量中有一个mpiexec.exe,而安装mpich2后环境变量同样也有mpiexec.exe,由此匹配错误造成如上问题,可修改其中一个程序名字...
也可通过wmpiexec(开始菜单,图形界面) 运行.
4.命令行下fortran程序编译,链接,以mpich\example\fpi.f 为例
program main
include 'mpif.h'
double precision PI25DT
parameter (PI25DT = 3.141592653589793238462643d0)
double precision mypi, pi, h, sum, x, f, a
integer n, myid, numprocs, i, rc
c function to integrate
f(a) = 4.d0 / (1.d0 + a*a)
call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
print *, "Process ", myid, " of ", numprocs, " is alive"
sizetype = 1
sumtype = 2
10 if ( myid .eq. 0 ) then
write(6,98)
98 format('Enter the number of intervals: (0 quits)')
read(5,99) n
99 format(i10)
endif
call MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
c check for quit signal
if ( n .le. 0 ) goto 30
c calculate the interval size
h = 1.0d0/n
sum = 0.0d0
do 20 i = myid+1, n, numprocs
x = h * (dble(i) - 0.5d0)
sum = sum + f(x)
20 continue
mypi = h * sum
c collect all the partial sums
call MPI_REDUCE(mypi,pi,1,MPI_DOUBLE_PRECISION,MPI_SUM,0,
$ MPI_COMM_WORLD,ierr)
c node 0 prints the answer.
if (myid .eq. 0) then
write(6, 97) pi, abs(pi - PI25DT)
97 format(' pi is approximately: ', F18.16,
+ ' Error is: ', F18.16)
endif
goto 10
30 call MPI_FINALIZE(rc)
stop
end命令行(vs6.0,compaq fortran):
df fpi.f /nolink
link fpi.obj fmpich2s.lib
或者:
df fpi.f fmpich2s.lib也可通过设置df变量实现自动调用fmpich2s.lib (详细参考vs 帮助文档 Using the DF Environment Variable to Specify Options)
set df=fmpich2s.lib
df fpi.f
For Visual Fortran 6 use fmpich2s.lib:
• fmpich2.lib contains all caps cdecl: MPI_INIT
• fmpich2s.lib contains all caps stdcall: MPI_INIT@4
• fmpich2g.lib or fmpich2g.a contain lowercase cdecl: mpi_init__
5.重新编译mpi.mod
mpich2/include 文件夹下包含以编译好的mpi.mod 因此在程序中可以通过 use mpi 调用mpi库
但在64位系统下,这个mpi.mod似乎不兼容。可以把mpif.h 内的变量声明等改写为module,编译一个mpi.mod出来,测试可用。
6.compaq visual fortran 下设置:
1.tools>options>directory 添加include ,lib(永久更改,下次不需重新设置)
2.project >settings>links>Object/libary modules/ 添加 fmpich2s.lib (每个工程需单独设置,也可 save fortran environment (工具栏-fortran-save fortran environment ) 下次可调用,参考vs帮助文档: Saving and Using the Project Setting Environment for Different Projects)
参考:
THE INSTALLER:
You must install MPICH2 on all machines that you want to run MPI programs on. Run the installer on each machine individually.
The installer creates the following mpich2 directory structure on your machine:
mpich2\bin
mpich2\include
mpich2\lib
The include and lib directories contain the libraries needed to compile MPI programs. The mpich2 dlls are copied to the Windows\system32 directory. The bin directory contains smpd.exe which is the MPICH2 process manager used to launch MPI programs. mpiexec.exe, also found in the bin directory, is used to start MPICH2 jobs.
COMPILING:
Compiling an MPI program:
1) Create a project for Visual Studio 2003, or Intel Fortran 8.0
2) Add mpich2\include to the include path
3) Add mpich2\lib to the library path
4) For C applications add mpi.lib to your target link command.
5) For Fortran applications add fmpich2.lib to the link command.
6) Compile
7) Place your application and all the dlls it depends on in a shared location or copy them to all the nodes.
8) Run the application using mpiexec
For Visual Fortran 6 use fmpich2s.lib:
• fmpich2.lib contains all caps cdecl: MPI_INIT
• fmpich2s.lib contains all caps stdcall: MPI_INIT@4
• fmpich2g.lib or fmpich2g.a contain lowercase cdecl: mpi_init__
For gcc/g77
1) create a makefile
2) add –I…mpich2\include
3) add –L…mpich2\lib
4) add –lmpi (for g77: -lfmpich2g)
5) add the rules for your source files
6) same as 6,7,8 above
RUNNING MPI JOBS:
mpiexec is a command line application used to launch MPI jobs. Bring up a command prompt to run it. Execute "mpiexec" to see the available options.
The simplest mpiexec command is like this:
mpiexec -n 3 myapp.exe
MINIMAL INSTALLATION:
If you want to have worker nodes that do not have any tools on them, you can simply copy smpd.exe to each node and execute "smpd.exe -install".
smpd.exe is the only application required on each machine to launch MPICH2 jobs. But, MPICH2 applications require the mpich2 dlls. This requirement can be satisfied by copying the mpich2 dlls to the windows\system32 directory on each node. Then any mpich2 application can run on those systems. This is what the installer does. If you don't want to copy the mpich2 dlls to each machine, then you need to place the dlls in the same location as the executable you are going to launch.
For example, if you have a directory called \\myserver\mysharedfolder and you have myapp.exe and *mpich2*.dll in that directory then you can execute this command: "mpiexec -n 4 \\myserver\mysharedfolder\myapp.exe"
Note: There are several mpich2 dlls and depending on your build target (Fortran, C, Debug or Release) you will need the corresponding dlls in the application directory.

本文介绍了在Windows 7环境下,如何配置MPICH以进行64位和32位的Fortran编译。在配置过程中,解决因MATLAB导致的MPI执行错误,并详细说明了使用命令行编译Fortran MPI程序的步骤,包括修改mpi.mod文件以适应64位系统。此外,还提到了在Compaq Visual Fortran中设置编译路径和链接库的方法。
1万+

被折叠的 条评论
为什么被折叠?



