MPI_Allgather receiving junk





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I have the following code:



              real          :: s_s, d_s, s_r(size), d_r(size)
integer :: k, k_r(size)

! - size = number of processors
! - Do something to initialise s_s, d_s, k
write(*,*) "SENDING >>>>"
write(*,*) s_s, d_s
call MPI_Allgather( s_s, 1, MPI_REAL,
& s_r, 1, MPI_REAL, MPI_COMM_PGM, mpi_err)

call MPI_Allgather( d_s, 1, MPI_REAL,
& d_r, 1, MPI_REAL, MPI_COMM_PGM, mpi_err)

call MPI_Allgather ( k, 1, MPI_INTEGER,
& k_r, 1, MPI_INTEGER, MPI_COMM_PGM, mpi_err)


write(*,*) "RECEIVED <<<<"
write(*,*) s_r, d_r, kr


This generates the following output:



SENDING >>>>
-1803.80339864908 0.616157856320407
RECEIVED <<<<
6.953077622513053E-310 3.565412685916647E-314 1.221334434576037E-314
1.498827614035474E-314 6.952991536467244E-310 6.953288052096687E-310
6.953108563966064E-310 2.350861403096908E-314 4 1
2 3


kr is being gathered correctly however, s_r and d_r seem to be receiving junk. Could this be because of the MPI datatypes? I tried with MPI_REAL MPI_REAL8 and MPI_DOUBLE but that didn't work. Furthermore, mpi_err = MPI_SUCCESS



What could I do to resolve this?



EDIT 1
I worked on the following prototype program:



program allgather
implicit none

include "mpif.h"

real a(4)
integer rank,size,ierr
real as(4)
real ar(16)
integer i, j, k,z

a=1
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
if(size.ne.4)then
write(*,*)'Error!:# of processors must be equal to 4'
write(*,*)'Programm aborting....'
call MPI_ABORT(ierr)
endif

do k=1,4
if ( rank == (mod(k, size))) then
a(k) = k
else
a(k) = 0.0
endif
enddo

write(*,*) "Rank :", rank
write(*,*) a

call MPI_Allgather(a, 4, MPI_REAL, ar,
& 4,
& MPI_REAL, MPI_COMM_WORLD, ierr)

write(*,*) "Recieved array"
write(*,*) ar

do i = 1, 16
if ( ar(i) /= 0.0 ) then
z = mod(i, size)
if ( z == 0 ) then
a( size ) = ar(i)
else
a ( z ) = ar(i)
endif
endif
enddo

write(*,*) "---------"
write(*,*) a
write(*,*) "---------"

call MPI_FINALIZE(ierr)
end


And this generates the expected results i.e. ar doesn't gather junk. I'm unable to however tell the difference between the implementations.










share|improve this question




















  • 1





    I can't see anything wrong with your first block right now. Can you minimally change that version (by setting some initial values for the values to pass) to be runnable while reproducing your issue? If you can't, odds are you removed something from your real code that is responsible for the bug.

    – Andras Deak
    Jan 3 at 23:07











  • One thing which is different is the communicator, I see that communicator MPI_COMM_PGM has been defined in another module. I use that module and specify the communicator in the code. A minimal example to reproduce the error would be quite verbose as this piece of code is embedded deep in a type bound method. Since it is sending the correct values, I presume there is an issue with only receiving.

    – newkid
    Jan 3 at 23:30








  • 4





    In that case you're asking us to debug code we can't see.

    – Andras Deak
    Jan 4 at 0:05











  • @AndrasDeak, understood! Will upload a minimal code shortly

    – newkid
    Jan 4 at 1:02






  • 2





    @AndrasDeak Indeed, the problem seems to be in another part of the code which controls buffer size. For now, I've solved the problem (see answer).

    – newkid
    Jan 4 at 2:00


















2















I have the following code:



              real          :: s_s, d_s, s_r(size), d_r(size)
integer :: k, k_r(size)

! - size = number of processors
! - Do something to initialise s_s, d_s, k
write(*,*) "SENDING >>>>"
write(*,*) s_s, d_s
call MPI_Allgather( s_s, 1, MPI_REAL,
& s_r, 1, MPI_REAL, MPI_COMM_PGM, mpi_err)

call MPI_Allgather( d_s, 1, MPI_REAL,
& d_r, 1, MPI_REAL, MPI_COMM_PGM, mpi_err)

call MPI_Allgather ( k, 1, MPI_INTEGER,
& k_r, 1, MPI_INTEGER, MPI_COMM_PGM, mpi_err)


write(*,*) "RECEIVED <<<<"
write(*,*) s_r, d_r, kr


This generates the following output:



SENDING >>>>
-1803.80339864908 0.616157856320407
RECEIVED <<<<
6.953077622513053E-310 3.565412685916647E-314 1.221334434576037E-314
1.498827614035474E-314 6.952991536467244E-310 6.953288052096687E-310
6.953108563966064E-310 2.350861403096908E-314 4 1
2 3


kr is being gathered correctly however, s_r and d_r seem to be receiving junk. Could this be because of the MPI datatypes? I tried with MPI_REAL MPI_REAL8 and MPI_DOUBLE but that didn't work. Furthermore, mpi_err = MPI_SUCCESS



What could I do to resolve this?



EDIT 1
I worked on the following prototype program:



program allgather
implicit none

include "mpif.h"

real a(4)
integer rank,size,ierr
real as(4)
real ar(16)
integer i, j, k,z

a=1
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
if(size.ne.4)then
write(*,*)'Error!:# of processors must be equal to 4'
write(*,*)'Programm aborting....'
call MPI_ABORT(ierr)
endif

do k=1,4
if ( rank == (mod(k, size))) then
a(k) = k
else
a(k) = 0.0
endif
enddo

write(*,*) "Rank :", rank
write(*,*) a

call MPI_Allgather(a, 4, MPI_REAL, ar,
& 4,
& MPI_REAL, MPI_COMM_WORLD, ierr)

write(*,*) "Recieved array"
write(*,*) ar

do i = 1, 16
if ( ar(i) /= 0.0 ) then
z = mod(i, size)
if ( z == 0 ) then
a( size ) = ar(i)
else
a ( z ) = ar(i)
endif
endif
enddo

write(*,*) "---------"
write(*,*) a
write(*,*) "---------"

call MPI_FINALIZE(ierr)
end


And this generates the expected results i.e. ar doesn't gather junk. I'm unable to however tell the difference between the implementations.










share|improve this question




















  • 1





    I can't see anything wrong with your first block right now. Can you minimally change that version (by setting some initial values for the values to pass) to be runnable while reproducing your issue? If you can't, odds are you removed something from your real code that is responsible for the bug.

    – Andras Deak
    Jan 3 at 23:07











  • One thing which is different is the communicator, I see that communicator MPI_COMM_PGM has been defined in another module. I use that module and specify the communicator in the code. A minimal example to reproduce the error would be quite verbose as this piece of code is embedded deep in a type bound method. Since it is sending the correct values, I presume there is an issue with only receiving.

    – newkid
    Jan 3 at 23:30








  • 4





    In that case you're asking us to debug code we can't see.

    – Andras Deak
    Jan 4 at 0:05











  • @AndrasDeak, understood! Will upload a minimal code shortly

    – newkid
    Jan 4 at 1:02






  • 2





    @AndrasDeak Indeed, the problem seems to be in another part of the code which controls buffer size. For now, I've solved the problem (see answer).

    – newkid
    Jan 4 at 2:00














2












2








2








I have the following code:



              real          :: s_s, d_s, s_r(size), d_r(size)
integer :: k, k_r(size)

! - size = number of processors
! - Do something to initialise s_s, d_s, k
write(*,*) "SENDING >>>>"
write(*,*) s_s, d_s
call MPI_Allgather( s_s, 1, MPI_REAL,
& s_r, 1, MPI_REAL, MPI_COMM_PGM, mpi_err)

call MPI_Allgather( d_s, 1, MPI_REAL,
& d_r, 1, MPI_REAL, MPI_COMM_PGM, mpi_err)

call MPI_Allgather ( k, 1, MPI_INTEGER,
& k_r, 1, MPI_INTEGER, MPI_COMM_PGM, mpi_err)


write(*,*) "RECEIVED <<<<"
write(*,*) s_r, d_r, kr


This generates the following output:



SENDING >>>>
-1803.80339864908 0.616157856320407
RECEIVED <<<<
6.953077622513053E-310 3.565412685916647E-314 1.221334434576037E-314
1.498827614035474E-314 6.952991536467244E-310 6.953288052096687E-310
6.953108563966064E-310 2.350861403096908E-314 4 1
2 3


kr is being gathered correctly however, s_r and d_r seem to be receiving junk. Could this be because of the MPI datatypes? I tried with MPI_REAL MPI_REAL8 and MPI_DOUBLE but that didn't work. Furthermore, mpi_err = MPI_SUCCESS



What could I do to resolve this?



EDIT 1
I worked on the following prototype program:



program allgather
implicit none

include "mpif.h"

real a(4)
integer rank,size,ierr
real as(4)
real ar(16)
integer i, j, k,z

a=1
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
if(size.ne.4)then
write(*,*)'Error!:# of processors must be equal to 4'
write(*,*)'Programm aborting....'
call MPI_ABORT(ierr)
endif

do k=1,4
if ( rank == (mod(k, size))) then
a(k) = k
else
a(k) = 0.0
endif
enddo

write(*,*) "Rank :", rank
write(*,*) a

call MPI_Allgather(a, 4, MPI_REAL, ar,
& 4,
& MPI_REAL, MPI_COMM_WORLD, ierr)

write(*,*) "Recieved array"
write(*,*) ar

do i = 1, 16
if ( ar(i) /= 0.0 ) then
z = mod(i, size)
if ( z == 0 ) then
a( size ) = ar(i)
else
a ( z ) = ar(i)
endif
endif
enddo

write(*,*) "---------"
write(*,*) a
write(*,*) "---------"

call MPI_FINALIZE(ierr)
end


And this generates the expected results i.e. ar doesn't gather junk. I'm unable to however tell the difference between the implementations.










share|improve this question
















I have the following code:



              real          :: s_s, d_s, s_r(size), d_r(size)
integer :: k, k_r(size)

! - size = number of processors
! - Do something to initialise s_s, d_s, k
write(*,*) "SENDING >>>>"
write(*,*) s_s, d_s
call MPI_Allgather( s_s, 1, MPI_REAL,
& s_r, 1, MPI_REAL, MPI_COMM_PGM, mpi_err)

call MPI_Allgather( d_s, 1, MPI_REAL,
& d_r, 1, MPI_REAL, MPI_COMM_PGM, mpi_err)

call MPI_Allgather ( k, 1, MPI_INTEGER,
& k_r, 1, MPI_INTEGER, MPI_COMM_PGM, mpi_err)


write(*,*) "RECEIVED <<<<"
write(*,*) s_r, d_r, kr


This generates the following output:



SENDING >>>>
-1803.80339864908 0.616157856320407
RECEIVED <<<<
6.953077622513053E-310 3.565412685916647E-314 1.221334434576037E-314
1.498827614035474E-314 6.952991536467244E-310 6.953288052096687E-310
6.953108563966064E-310 2.350861403096908E-314 4 1
2 3


kr is being gathered correctly however, s_r and d_r seem to be receiving junk. Could this be because of the MPI datatypes? I tried with MPI_REAL MPI_REAL8 and MPI_DOUBLE but that didn't work. Furthermore, mpi_err = MPI_SUCCESS



What could I do to resolve this?



EDIT 1
I worked on the following prototype program:



program allgather
implicit none

include "mpif.h"

real a(4)
integer rank,size,ierr
real as(4)
real ar(16)
integer i, j, k,z

a=1
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
if(size.ne.4)then
write(*,*)'Error!:# of processors must be equal to 4'
write(*,*)'Programm aborting....'
call MPI_ABORT(ierr)
endif

do k=1,4
if ( rank == (mod(k, size))) then
a(k) = k
else
a(k) = 0.0
endif
enddo

write(*,*) "Rank :", rank
write(*,*) a

call MPI_Allgather(a, 4, MPI_REAL, ar,
& 4,
& MPI_REAL, MPI_COMM_WORLD, ierr)

write(*,*) "Recieved array"
write(*,*) ar

do i = 1, 16
if ( ar(i) /= 0.0 ) then
z = mod(i, size)
if ( z == 0 ) then
a( size ) = ar(i)
else
a ( z ) = ar(i)
endif
endif
enddo

write(*,*) "---------"
write(*,*) a
write(*,*) "---------"

call MPI_FINALIZE(ierr)
end


And this generates the expected results i.e. ar doesn't gather junk. I'm unable to however tell the difference between the implementations.







fortran mpi openmpi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 23:30







newkid

















asked Jan 3 at 21:36









newkidnewkid

845518




845518








  • 1





    I can't see anything wrong with your first block right now. Can you minimally change that version (by setting some initial values for the values to pass) to be runnable while reproducing your issue? If you can't, odds are you removed something from your real code that is responsible for the bug.

    – Andras Deak
    Jan 3 at 23:07











  • One thing which is different is the communicator, I see that communicator MPI_COMM_PGM has been defined in another module. I use that module and specify the communicator in the code. A minimal example to reproduce the error would be quite verbose as this piece of code is embedded deep in a type bound method. Since it is sending the correct values, I presume there is an issue with only receiving.

    – newkid
    Jan 3 at 23:30








  • 4





    In that case you're asking us to debug code we can't see.

    – Andras Deak
    Jan 4 at 0:05











  • @AndrasDeak, understood! Will upload a minimal code shortly

    – newkid
    Jan 4 at 1:02






  • 2





    @AndrasDeak Indeed, the problem seems to be in another part of the code which controls buffer size. For now, I've solved the problem (see answer).

    – newkid
    Jan 4 at 2:00














  • 1





    I can't see anything wrong with your first block right now. Can you minimally change that version (by setting some initial values for the values to pass) to be runnable while reproducing your issue? If you can't, odds are you removed something from your real code that is responsible for the bug.

    – Andras Deak
    Jan 3 at 23:07











  • One thing which is different is the communicator, I see that communicator MPI_COMM_PGM has been defined in another module. I use that module and specify the communicator in the code. A minimal example to reproduce the error would be quite verbose as this piece of code is embedded deep in a type bound method. Since it is sending the correct values, I presume there is an issue with only receiving.

    – newkid
    Jan 3 at 23:30








  • 4





    In that case you're asking us to debug code we can't see.

    – Andras Deak
    Jan 4 at 0:05











  • @AndrasDeak, understood! Will upload a minimal code shortly

    – newkid
    Jan 4 at 1:02






  • 2





    @AndrasDeak Indeed, the problem seems to be in another part of the code which controls buffer size. For now, I've solved the problem (see answer).

    – newkid
    Jan 4 at 2:00








1




1





I can't see anything wrong with your first block right now. Can you minimally change that version (by setting some initial values for the values to pass) to be runnable while reproducing your issue? If you can't, odds are you removed something from your real code that is responsible for the bug.

– Andras Deak
Jan 3 at 23:07





I can't see anything wrong with your first block right now. Can you minimally change that version (by setting some initial values for the values to pass) to be runnable while reproducing your issue? If you can't, odds are you removed something from your real code that is responsible for the bug.

– Andras Deak
Jan 3 at 23:07













One thing which is different is the communicator, I see that communicator MPI_COMM_PGM has been defined in another module. I use that module and specify the communicator in the code. A minimal example to reproduce the error would be quite verbose as this piece of code is embedded deep in a type bound method. Since it is sending the correct values, I presume there is an issue with only receiving.

– newkid
Jan 3 at 23:30







One thing which is different is the communicator, I see that communicator MPI_COMM_PGM has been defined in another module. I use that module and specify the communicator in the code. A minimal example to reproduce the error would be quite verbose as this piece of code is embedded deep in a type bound method. Since it is sending the correct values, I presume there is an issue with only receiving.

– newkid
Jan 3 at 23:30






4




4





In that case you're asking us to debug code we can't see.

– Andras Deak
Jan 4 at 0:05





In that case you're asking us to debug code we can't see.

– Andras Deak
Jan 4 at 0:05













@AndrasDeak, understood! Will upload a minimal code shortly

– newkid
Jan 4 at 1:02





@AndrasDeak, understood! Will upload a minimal code shortly

– newkid
Jan 4 at 1:02




2




2





@AndrasDeak Indeed, the problem seems to be in another part of the code which controls buffer size. For now, I've solved the problem (see answer).

– newkid
Jan 4 at 2:00





@AndrasDeak Indeed, the problem seems to be in another part of the code which controls buffer size. For now, I've solved the problem (see answer).

– newkid
Jan 4 at 2:00












1 Answer
1






active

oldest

votes


















2














It turns out that for the project, the data type to be used was MPI_FLT. It is strange that MPI_FLT works and not MPI_REALx where x=4,8 also not MPI_FLOAT. I grep-ed MPI_FLT in the project to see what it is defined as but didn't turn up anywhere in the project.



The OpenMPI version I'm using is:



$ mpirun --version
mpirun (Open MPI) 3.0.0


The compiler I use is:



$ mpifort --version
ifort (IFORT) 19.0.1.144 20181018


In a future edit I will elaborate on the cause.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030138%2fmpi-allgather-receiving-junk%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    It turns out that for the project, the data type to be used was MPI_FLT. It is strange that MPI_FLT works and not MPI_REALx where x=4,8 also not MPI_FLOAT. I grep-ed MPI_FLT in the project to see what it is defined as but didn't turn up anywhere in the project.



    The OpenMPI version I'm using is:



    $ mpirun --version
    mpirun (Open MPI) 3.0.0


    The compiler I use is:



    $ mpifort --version
    ifort (IFORT) 19.0.1.144 20181018


    In a future edit I will elaborate on the cause.






    share|improve this answer




























      2














      It turns out that for the project, the data type to be used was MPI_FLT. It is strange that MPI_FLT works and not MPI_REALx where x=4,8 also not MPI_FLOAT. I grep-ed MPI_FLT in the project to see what it is defined as but didn't turn up anywhere in the project.



      The OpenMPI version I'm using is:



      $ mpirun --version
      mpirun (Open MPI) 3.0.0


      The compiler I use is:



      $ mpifort --version
      ifort (IFORT) 19.0.1.144 20181018


      In a future edit I will elaborate on the cause.






      share|improve this answer


























        2












        2








        2







        It turns out that for the project, the data type to be used was MPI_FLT. It is strange that MPI_FLT works and not MPI_REALx where x=4,8 also not MPI_FLOAT. I grep-ed MPI_FLT in the project to see what it is defined as but didn't turn up anywhere in the project.



        The OpenMPI version I'm using is:



        $ mpirun --version
        mpirun (Open MPI) 3.0.0


        The compiler I use is:



        $ mpifort --version
        ifort (IFORT) 19.0.1.144 20181018


        In a future edit I will elaborate on the cause.






        share|improve this answer













        It turns out that for the project, the data type to be used was MPI_FLT. It is strange that MPI_FLT works and not MPI_REALx where x=4,8 also not MPI_FLOAT. I grep-ed MPI_FLT in the project to see what it is defined as but didn't turn up anywhere in the project.



        The OpenMPI version I'm using is:



        $ mpirun --version
        mpirun (Open MPI) 3.0.0


        The compiler I use is:



        $ mpifort --version
        ifort (IFORT) 19.0.1.144 20181018


        In a future edit I will elaborate on the cause.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 1:58









        newkidnewkid

        845518




        845518
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030138%2fmpi-allgather-receiving-junk%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'