title: Having an issue with MPI_GATHER/MPI_GATHERV in F90 with derived data types
body: <p>I have a task in which I will have several data types together; character, several integers, and a double precision value, which represent a solution to a problem.</p>
  
  <p>At the moment, I have a "toy" F90 program, that uses MPI with random numbers and a contrived character string for each processor.  I want to have a data type that has the character and the double precision random number together.</p>
  
  <p>I will use MPI_REDUCE to get the minimum value for the double precision values.  I will have the data type for each process brought together to the root (rank = 0) via the MPI_GATHERV function.</p>
  
  <p>My goal is to match up the minimum value from the random values to the data type.  That would be the final answer.  I have tried all sort of ideas up to this point, but to no avail.  I end up with "forrtl: severe SIGSEGV, segmentation fault occurred".</p>
  
  <p>Now I have looked at several of the other postings too.  For instance, I cannot use the "use mpif.h" statement on this particular system.</p>
  
  <p>But, at last, here is the code:</p>
  
  <pre><code>program fredtype
    implicit none
    include '/opt/apps/intel15/mvapich2/2.1/include/mpif.h'
  
  
  
    integer rank,size,ierror,tag,status(MPI_STATUS_SIZE),i,np,irank
    integer blocklen(2),type(2),num,rcount(4)
    double precision :: x,aout
    character(len=4) :: y
  
    type, BIND(C) :: mytype
       double precision :: x,aout,test
       character :: y
    end type mytype
  
    type(mytype) :: foo,foobag(4)
    integer(KIND=MPI_ADDRESS_KIND) :: disp(2),base
  
  
    call MPI_INIT(ierror)
  
   call MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierror)
    call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierror)
  
    aout = 99999999999.99
  
    call random_seed()
    call random_number(x)
  
  
  
    if(rank.eq.0)y="dogs"
    if(rank.eq.1)y="cats"
    if(rank.eq.2)y="tree"
    if(rank.eq.3)y="woof"
  
    print *,rank,x,y
  
  
    call MPI_GET_ADDRESS(foo%x,disp(1),ierror)
    call MPI_GET_ADDRESS(foo%y,disp(2),ierror)
  
    base = disp(1)
   call MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierror)
    call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierror)
  
    aout = 99999999999.99
  
    call random_seed()
    call random_number(x)
  
  
  
    if(rank.eq.0)y="dogs"
    if(rank.eq.1)y="cats"
    if(rank.eq.2)y="tree"
    if(rank.eq.3)y="woof"
  
    print *,rank,x,y
  
  
    call MPI_GET_ADDRESS(foo%x,disp(1),ierror)
    call MPI_GET_ADDRESS(foo%y,disp(2),ierror)
  
    base = disp(1)
   call MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierror)
    call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierror)
  
    aout = 99999999999.99
  
    call random_seed()
    call random_number(x)
  
  
  
    if(rank.eq.0)y="dogs"
    if(rank.eq.1)y="cats"
    if(rank.eq.2)y="tree"
    if(rank.eq.3)y="woof"
  
    print *,rank,x,y
  
  
    call MPI_GET_ADDRESS(foo%x,disp(1),ierror)
    call MPI_GET_ADDRESS(foo%y,disp(2),ierror)
  
    base = disp(1)
    disp(2) = disp(2) - base
  
    blocklen(1) = 1
    blocklen(2) = 1
  
    type(1) = MPI_DOUBLE_PRECISION
    type(2) = MPI_CHARACTER
  
  
    call MPI_TYPE_CREATE_STRUCT(2,blocklen,disp,type,foo,ierror)
    call MPI_TYPE_COMMIT(foo,ierror)
  
  
  
  
         call MPI_REDUCE(x,aout,1,MPI_DOUBLE_PRECISION,MPI_MIN,0,MPI_COMM_WORLD,i\
  error)
  
         call MPI_GATHER(num,1,MPI_INT,rcount,1,MPI_INT,0,MPI_COMM_WORLD)
         call MPI_GATHERV(foo,num,type,foobag,rcount,disp,type,0,MPI_COMM_WORLD)
  
  
         if(rank.eq.0)then
             print *,'fin ',aout
  
            end if
  
  
  
  
  end program fredtype
  </code></pre>
  
  <p>Thank you for any help.
  Sincerely,
  Erin</p>