Note that there are some explanatory texts on larger screens.

plurals
  1. POMPI_ALLGATHER error parallelizing code
    primarykey
    data
    text
    <p>I'm trying to parallelize the following code.</p> <pre><code>subroutine log_likelihood(y, theta, lli, ll) doubleprecision, allocatable, intent(in) :: y(:) doubleprecision, intent(in) :: theta(2) doubleprecision, allocatable, intent(out) :: lli(:) doubleprecision, intent(out) :: ll integer :: i ALLOCATE (lli(size(y))) lli = 0.0d0 ll = 0.0d0 do i = 1, size(y) lli(i) = -log(sqrt(theta(2))) - 0.5*log(2.0d0*pi) &amp; - (1.0d0/(2.0d0*theta(2)))*((y(i)-theta(1))**2) end do ll = sum(lli) end subroutine log_likelihood </code></pre> <p>To do this, I'm trying to use MPI_ALLGATHER. This is the code I wrote</p> <pre><code>subroutine log_likelihood(y, theta, lli, ll) doubleprecision, allocatable, intent(in) :: y(:) doubleprecision, intent(in) :: theta(2) doubleprecision, allocatable, intent(out) :: lli(:) doubleprecision, intent(out) :: ll integer :: i, size_y, diff size_y=size(y) ALLOCATE (lli(size_y)) !Broadcasting call MPI_BCAST(theta, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr) call MPI_BCAST(y, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr) ! Determine how many points to handle with each proc points_per_proc = (size_y + numprocs - 1)/numprocs ! Determine start and end index for this proc's points istart = proc_num * points_per_proc + 1 iend = min((proc_num + 1)*points_per_proc, size_y) diff = iend-istart+1 allocate(proc_contrib(istart:iend)) do i = istart, iend proc_contrib(i) = -log(sqrt(theta(2))) - 0.5*log(2.0d0*pi) &amp; - (1.0d0/(2.0d0*theta(2)))*((y(i)-theta(1))**2) end do call MPI_ALLGATHER(proc_contrib, diff, MPI_DOUBLE_PRECISION, &amp; lli, diff, MPI_DOUBLE_PRECISION, &amp; MPI_COMM_WORLD, ierr) ll = sum(lli) end subroutine log_likelihood </code></pre> <p>When I try to run my program, I get the following error.</p> <pre><code>$ mpiexec -n 2 ./mle.X Fatal error in PMPI_Allgather: Internal MPI error!, error stack: PMPI_Allgather(961)......: MPI_Allgather(sbuf=0x7ff2f251b860, scount=1500000, MPI_DOUBLE_PRECISION, rbuf=0x7ff2f2ad5650, rcount=3000000, MPI_DOUBLE_PRECISION, MPI_COMM_WORLD) failed MPIR_Allgather_impl(807).: MPIR_Allgather(766)......: MPIR_Allgather_intra(560): MPIR_Localcopy(357)......: memcpy arguments alias each other, dst=0x7ff2f2ad5650 src=0x7ff2f251b860 len=12000000 =================================================================================== = BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES = EXIT CODE: 1 = CLEANING UP REMAINING PROCESSES = YOU CAN IGNORE THE BELOW CLEANUP MESSAGES =================================================================================== </code></pre> <p>Can somebody please explain to me what I'm doing wrong? </p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COYou're writing into `proc_contrib(istart:iend)` but you've allocated it to go from 1:diff; ranks 1 and above will overwrite the end of proc_contrib which probably causes the issue. (There's also a bunch of missing variables; numproc, etc). Further the allgather tries to read outside the bounds of the array. You can `allocate(proc_contrib(istart:iend))` and change the call to allgatherv, etc. Also, you don't really need to do an allgather; an [`MPI_Allreduce`](http://www.mcs.anl.gov/research/projects/mpi/www/www3/MPI_Allreduce.html) will do the sum for you which is all you need here.
      singulars
    2. COIn fact, I'd suggest not modifying the routine, but doing the sum outside.  Ideally, you wouldn't have each processor "know" all the `y(i)`s; they'd just have their own local piece of the problem, call the `log_likelihood` routine, and then allreduce the partial sums (or just reduce if the log likelihood is the final result and it just needs to be printed out).
      singulars
    3. CO1. The missing variables are all declared as globals outside that subroutine. 2. I understant my first mistake, and i changed to allocate(proc_contrib(istart:iend)) 3. Can you please explain me how to fix the Allgather? I need an Allgather because in my real program I need lli as an output. Thanks!
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload