Anthony Zealous
Anthony Zealous

Reputation: 25

Fatal error in MPI_Send, invalid tag

I am fairly new to writing/running parallel code. Currently I am experimenting with basic tutorials in writing parallel code to obtain a feel for the process. My computer is using ubuntu with Mpich.

I am attempting to run the code entitled "The complete parallel program to sum a vector" on this page :http://condor.cc.ku.edu/~grobe/docs/intro-MPI.shtml

and am encountering the following error upon execution after being prompted for/entering a number:

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

I also receive the warning while compiling:

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)

This is my code

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

Upvotes: 1

Views: 2395

Answers (1)

You are missing IMPLICIT NONE and you have a large number of undeclared variables.

The reported error is because

 send_data_tag = 2001, return_data_tag = 2002

are implicitly real variables and not integers. But you probably have many more problems.

First add IMPLICIT NONE and declare or variables. Also I highly recommend to put use mpi instead of the include '/usr/include/mpi/mpif.h' it is likely to help you to find more problems.


Now I see the code is copied from some website. I wouldn't trust this website, because the codes are clearly wrong.

Upvotes: 2

Related Questions