MPI_Send 中的致命错误,无效标记

Fatal error in MPI_Send, invalid tag

我对 writing/running 并行代码还很陌生。目前,我正在尝试编写并行代码的基本教程,以获得对该过程的感觉。我的电脑正在使用 ubuntu 和 Mpich。

我正在尝试 运行 此页面上名为 "The complete parallel program to sum a vector" 的代码:http://condor.cc.ku.edu/~grobe/docs/intro-MPI.shtml

在提示 for/entering 一个数字后执行时遇到以下错误:

Fatal error in MPI_Send: Invalid tag, error stack:
MPI_Send(174): MPI_Send(buf=0x7ffeab0f2d3c, count=1, MPI_INT, dest=1, tag=1157242880, MPI_COMM_WORLD) failed
MPI_Send(101): Invalid tag, value is 1157242880

我在编译时也收到警告:

sumvecp.f90:41:23:

   call mpi_send(vector(start_row),num_rows_to_send, mpi_real, an_id, send_data_tag, mpi_comm_world,ierr)
                       1
Warning: Legacy Extension: REAL array index at (1)

这是我的代码

program sumvecp

include '/usr/include/mpi/mpif.h'

parameter (max_rows = 10000000)
parameter (send_data_tag = 2001, return_data_tag = 2002)

integer my_id, root_proces, ierr, status(mpi_status_size)
integer num_procs, an_id, num_rows_to_receive
integer avg_rows_per_process, num_rows,num_rows_to_send

real vector(max_rows), vector2(max_rows), partial_sum, sum


root_process = 0

call mpi_init(ierr)

call mpi_comm_rank(mpi_comm_world,my_id,ierr)
call mpi_comm_size(mpi_comm_world,num_procs,ierr)

if (my_id .eq. root_process) then
    print *, "please enter the number of numbers to sum: "
    read *, num_rows
    if (num_rows .gt. max_rows) stop "Too many numbers."

    avg_rows_per_process = num_rows / num_procs

    do ii = 1,num_rows
        vector(ii) = float(ii)
    end do

    do an_id = 1, num_procs -1
        start_row = (an_id*avg_rows_per_process) +1
        end_row = start_row + avg_rows_per_process -1
        if (an_id .eq. (num_procs - 1)) end_row = num_rows
        num_rows_to_send = end_row - start_row + 1

        call mpi_send(num_rows_to_send, 1, mpi_int, an_id, send_data_tag, mpi_comm_world,ierr)

        call mpi_send(vector(start_row),num_rows_to_send, mpi_real, an_id, send_data_tag, mpi_comm_world,ierr)
    end do

    summ = 0.0
    do ii = 1, avg_rows_per_process
        summ = summ + vector(ii)
    end do

    print *,"sum", summ, "calculated by the root process."

    do an_id =1, num_procs -1
        call mpi_recv(partial_sum, 1, mpi_real, mpi_any_source, mpi_any_tag, mpi_comm_world, status, ierr)

        sender = status(mpi_source)
        print *, "partial sum", partial_sum, "returned from process", sender
        summ = summ + partial_sum
    end do

    print *, "The grand total is: ", sum

else
    call mpi_recv(num_rows_to_receive, 1, mpi_int, root_process, mpi_any_tag, mpi_comm_world,status,ierr)

    call mpi_recv(vector2,num_rows_to_received, mpi_real,root_process,mpi_any_tag,mpi_comm_world,status,ierr)

    num_rows_received = num_rows_to_receive

    partial_sum = 0.0
    do ii=1,num_rows_received
        partial_sum = partial_sum + vector2(ii)
    end do

    call mpi_send(partial_sum,1,mpi_real,root_process,return_data_tag,mpi_comm_world,ierr)
endif

call mpi_finalize(ierr)
stop
end

您缺少 IMPLICIT NONE 并且您有大量未声明的变量。

报错是因为

 send_data_tag = 2001, return_data_tag = 2002

是隐含的 real 变量而不是 integer。但你可能还有更多问题。

首先添加 IMPLICIT NONE 并声明或变量。此外,我强烈建议使用 use mpi 而不是 include '/usr/include/mpi/mpif.h',这可能会帮助您找到更多问题。


现在我看到代码是从某个网站复制的。我不会相信这个网站,因为代码显然是错误的。