Contiguous Derived Datatype: C Example

 

        program type_contiguous
        include "mpif.h"
        integer ibuf(20)
        integer rank,size,ierr

        call MPI_INIT(ierr)
        call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
        call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)

        if (rank==0) then
           do i = 1, 20
              ibuf(i) = i
           enddo
        endif

        call MPI_TYPE_CONTIGUOUS(5, MPI_INTEGER, inewtype, ierr)
        call MPI_TYPE_COMMIT(inewtype, ierr)
        call MPI_BCAST(ibuf, 2, inewtype, 0, MPI_COMM_WORLD, ierr)
        write(*,*) 'ibuf =', ibuf

        call MPI_FINALIZE(ierr)

        end