Module mpi3 implicit none include "mpif.h" ! Exemplary derived type for a communicator Type MPI_Comm Private Type (C_ptr) :: MPIR_comm_ptr Integer :: Other_process_dependent_mpi_data Integer :: More_process_dependent_mpi_data End Type MPI_Comm End Module mpi3 program bcast_derived_type use mpi3 Implicit none ! Derived User type containing a communicator Type My_type Integer :: my_int Integer, Pointer :: pointer1 Double Precision, Pointer :: pointer2 Type (MPI_Comm) :: my_comm End Type My_type Type (My_type) :: var1 Integer :: ierror, len call MPI_Init (ierror) call MPI_Comm_dup (MPI_COMM_WORLD, var1%my_comm, ierror) ! Some time later; overloaded by several interface descriptions ! a MPI_Bcast is executed for "var1" ! This will overwrite the data of "var1" in the non-root processes ! ! I know that this is not portable and that this is not intened by MPI. ! But I have seen such usage of derived types in application programs. ! Application programmers use this byte stream since it's ! too "difficult" to set up a derived MPI datatype for large ! Fortran derived tyes and since this works on "all" (they claim) systems. ! Get size (in bytes) of derived type "my_type" ! Size includes size of type MPI_Comm len = size (transfer (var1, (/' '/))) call MPI_Bcast (var1, len, MPI_BYTE, 0, MPI_COMM_WORLD, ierror) ! After that, the process dependent data of "my_comm" is changed and ! usage of my_comm may result in very strange problems. ! call MPI_Finalize (ierror) end