0

I dont understand why the following program is not working. When I am running it with "mpirun -np 2 a.out" I would expect it to print "N: 2" but instead it is giving me a seg fault.

Thank you

main.f

  program main

  implicit none

  include 'mpif.h'

  integer me, ngs,ierror

  call  inimpi(me, ngs)

  call calc

  call mpi_finalize( ierror )

  stop
  end

inimpi.f

  subroutine  inimpi(me, ngs)

  include  'mpif.h'

  integer me, ngs, ierror

  call  mpi_init( ierror )
  call  mpi_comm_rank( mpi_comm_world, me,  ierror )
  call  mpi_comm_size( mpi_comm_world, ngs, ierror )

  return
  end

calc.f

  subroutine  calc

  include 'mpif.h'

  integer  p, e, ierror

  p = 1

  call mpi_reduce(p, e, 1, mpi_integer,
 &     mpi_sum, mpi_comm_world, ierror)

  print *, "N: ", e
  return
  end

1 Answer 1

3

Taken from the mpich2 documentation:

int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, 
               MPI_Op op, int root, MPI_Comm comm)

You didn't specify the root for mpi_reduce. Because of this, mpi_comm_world is used as root and ierror is used as MPI_Comm. Did you mean to use MPI_Allreduce, which doesn't need a root argument?

Oh, and try to use use mpi instead of include 'mpif.h' if possible, this might have even caught the current error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.