1. 程式人生 > >win7下mpich配置及fortran編譯(64位及32位)

win7下mpich配置及fortran編譯(64位及32位)

通過如下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