回 帖 发 新 帖 刷新版面

主题:求哪位大侠看下面程序是否能正常运行,我运行几次都是错误百出,谢谢!

program cannon_on_square_grid
  include 'mpif.h'
  integer myid, nproc, comm, ierr
  integer dest, sour, left, right, upper, lower
  integer maxlen, maxn, nps, n, status(mpi_status_size)
  parameter (n=400,maxlen=n*n+1)
  real*8 a(maxlen), b(maxlen), c(maxlen)
  real*8 t1, t2, flops, perfs

  Initialize communicator.
  call mpi_init( ierr )
  call mpi_comm_dup( mpi_comm_world, comm, ierr )
  call mpi_comm_rank( comm, rnyid, ierr )
  call mpi_comm_size( comm, nproc, ierr )
  nps = sqrt(nproc*1.0)
  if(nps*nps. ne. nproc. or. mod(n, nps). ne. 0)goto 999
  m=n/nps
 
 Initialize matrices.
  myrow = mod(myid,nps)
  mycol = myid/nps
  do 10 j = 1, m
  do 10 i = 1, m
   a(i+(j-1)*m) = (myrow*m+i)*n+mycol*m+j
   b(i+(j-1)*m) = (myrow*m+i)*n*n+mycol*m+j
 10 continue

  t1=mpi_wtime()

 A1ignment of matrix A.
  dest = myrow + mod(mycol-myrow+nps,nps)*nps
  sour = myrow + mod(mycol+myrow,nps)*nps
  call mpi_sendrecv_replace(a, m*m, mpi_double_precision, dest, 10, & sour, 10, comm, status, ierr)

 A1ignment of matrix B.
  dest = mod(myrow-mycol + nps, nps) + mycol*nps
  sour = mod(mycol + myrow, nps) + mycol*nps
  call mpi_sendrecv_replace(b, m*m, mpi_double_precision, dest, 20, & sour, 20, comm, status, ierr)

 Initialize of matrix C.
  do 20 j = 1, m
  do 20 i = 1, m
  c(i + (j-1)*m)=0.0
 20 continue

 Main procedure.
  left = myrow + mod(mycol-1+nps,nps)*nps
  upper = mod(myrow-1+nps,nps) + mycol*nps
  right = myrow + mod(mycol+1,nps)*nps
  lower = mod(myrow+1,nps) + mycol*nps
  do 30 k=0, nps-1
   call dgemm('n', 'n', m, m, m, 1.0D0, a, m, b, m, 1.0D0, c, m)
   call mpi_sendrecv_replace(a, m*m, mpi_double_precision, left, & k+1, right, k+1, comm, status, ierr)
   call mpi_sendrecv_replace(b, m*m, mpi_double_precision, upper, & k+1+nps, lower, k+1+nps comm, status, ierr)
 30 continue

 Reverse alignment of matrix A.
  sour = myrow + mod(mycol-myrow+nps, nps)*nps
  dest = myrow + mod(mycol+myrow, nps)*nps
  call mpi_sendrecv_replace(a, m*m, mpi_double_precision, dest, 100, & sour, 100, comm, status, ierr)

 Reverse alignment of matrix B.
  sour = mod(myrow-mycol+nps, nps) + mycol*nps
  dest = mod(mycol+myrow, nps) + mycol*nps
  call mpi_sendrecv_replace(b, m*m, mpi_double_precision, dest, 200, & sour, 200, comm, status, ierr)

  t2 = mpi_wtime()
  flops = 2.0d-6*n*n*n
  perfs = flops/(t2-t1)
  write(*,*)n, nprow, npcol, myid, perfs
 999 call mpi_comm_free(comm, ierr)
  call mpi_finalize(ierr)
  stop
  end

回复列表 (共11个回复)

沙发

楼主到底要用固定格式还是自由格式?
自由格式那就不能用C来做注释;
而固定格式嘛。。。这程序明显不符要求。。。

换个方式问:楼主这个程序源码的文件名是啥?(重点是扩展名)

板凳

还有, 这个是含MPI的程序, 使用了MPI的编译命令?

3 楼

所给程序为稠密矩阵相乘的Cannon算法,扩展名为.f90
不好意思,我是个新手,有些东西不太懂......

4 楼

f90就是自由格式了. 但一些注释前面没有加叹号, 不知道是笔误还是什么.
这个代码使用了mpi并行. 是需要装mpi库和mpi编译命令编译的.

5 楼

编辑时出现以下错误应该怎么办?
错误    1    The Fortran compiler (ifort.exe) cannot be found.        

6 楼

你看看有没有装好fortran编译器.

7 楼

现在编译中没有错误了,但在调试时却出现下面错误,不知应该怎样修改

错误    1     error LNK2019: 无法解析的外部符号 _DGEMM,该符号在函数 _MAIN__ 中被引用    Source1.obj    

错误    2     fatal error LNK1120: 1 个无法解析的外部命令    Debug\Source1.exe    

8 楼

这是链接错误,还没到调试呢。。。
DGEMM是BLAS里的函数,你的工程里包含了这个东东么?

9 楼

program cannon_on_square_grid
  include "mpif.h"
  integer myid, nproc, comm, ierr
  integer dest, sour, left, right, upper, lower
  integer maxlen, maxn, nps, n, status(mpi_status_size)
  parameter (n = 400,maxlen = n*n + 1)
  real*8 a(maxlen), b(maxlen), c(maxlen)
  real*8 t1, t2, flops, perfs
!c
!c Initialize communicator.
   call mpi_init( ierr )
   call mpi_comm_dup(mpi_comm_world,comm,ierr)
   call mpi_comm_rank(comm,myid,ierr)
   call mpi_comm_size( comm, nproc, ierr )
   nps = sqrt(nproc*1.0)
   if(nps*nps.ne.nproc.or.mod(n,nps).ne.0)goto 999
   m=n/nps
!c 
!c Initialize matrices.
myrow=mod(myid,nps)
mycol=myid/nps
    do 10 j=1, m
    do 10 i=1, m
      a(i + (j-1)*m) = (myrow*m + i)*n + mycol*m + j
b(i + (j-1)*m) = (myrow*m + i)*n*n + mycol*m + j
 10 continue
!c
  t1=mpi_wtime()
!c
!c A1ignment of matrix A.
    dest = myrow + mod(mycol-myrow + nps,nps) * nps
    sour = myrow + mod(mycol + myrow,nps) * nps
    call mpi_sendrecv_replace(a, m*m, mpi_double_precision, dest, 10, & sour, 10, comm, status, ierr)
!c
!c A1ignment of matrix B.
    dest = mod(myrow-mycol + nps, nps) + mycol*nps
sour = mod(mycol + myrow, nps) + mycol * nps
    call mpi_sendrecv_replace(b, m*m, mpi_double_precision, dest, 20, & sour, 20, comm, status, ierr)
!c
!c Initialize of matrix C.
    do 20 j = 1, m
    do 20 i = 1, m
      c(i + (j-1)*m)=0.0
   20 continue
!c
!c Main procedure.
    left = myrow + mod(mycol-1 + nps,nps)*nps
    upper = mod(myrow-1 + nps,nps) + mycol*nps
right = myrow + mod(mycol + 1,nps)*nps
lower = mod(myrow + 1,nps) + mycol*nps
    do 30 k=0, nps-1
      call dgemm('n', 'n', m, m, m, 1.0D0, a, m, b, m, 1.0D0, c, m)
      call mpi_sendrecv_replace(a, m*m, mpi_double_precision, left, & k + 1, right, k + 1, comm, status, ierr)
call mpi_sendrecv_replace(b, m*m, mpi_double_precision, upper, & k + 1 + nps, lower, k + 1 + nps, comm, status, ierr)
 30 continue
!c
!c Reverse alignment of matrix A.
sour = myrow + mod(mycol-myrow + nps, nps)*nps
dest = myrow + mod(mycol + myrow, nps)*nps
call mpi_sendrecv_replace(a, m*m, mpi_double_precision, dest, 100, & sour, 100, comm, status, ierr)
!c
!c Reverse alignment of matrix B.
sour = mod(myrow-mycol + nps, nps) + mycol*nps
dest = mod(mycol + myrow, nps) + mycol*nps
    call mpi_sendrecv_replace(b, m*m, mpi_double_precision, dest, 200, & sour, 200, comm, status, ierr)
!c
t2 = mpi_wtime()
flops = 2.0d-6*n*n*n
perfs = flops/(t2-t1)
    write(*,*)n, nprow, npcol, myid, perfs
999 call mpi_comm_free(comm, ierr)
    call mpi_finalize(ierr)
    stop
    end

但是该程序在编译过程中却显示如下:
------ Build started: Project: Source1, Configuration: Debug|Win32 ------

Compiling with Intel(R) Fortran 11.0.061 [IA-32]...
Source1.F90

Build log written to  "file://C:\Documents and Settings\Administrator\桌面\86\Debug\BuildLog.htm"
Source1 - 0 error(s), 0 warning(s)


---------------------- Done ----------------------

下一步不就应该进行调试了吗?

10 楼

编译没有错就试运行一下吧.

我来回复

您尚未登录,请登录后再回复。点此登录或注册