MPIを初期化して rank / size を取得する。非MPIビルドでは単一ランクを返す。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mpi_context), | intent(out) | :: | ctx |
subroutine mpi_initialize(ctx) type(mpi_context), intent(out) :: ctx #ifdef USE_MPI include 'mpif.h' logical :: is_initialized integer :: ierr integer :: rank_int, size_int #endif ctx = mpi_context() #ifdef USE_MPI call MPI_Initialized(is_initialized, ierr) if (.not. is_initialized) then call MPI_Init(ierr) ctx%initialized_here = .true. end if call MPI_Comm_rank(MPI_COMM_WORLD, rank_int, ierr) call MPI_Comm_size(MPI_COMM_WORLD, size_int, ierr) ctx%rank = int(rank_int, i32) ctx%size = int(size_int, i32) ctx%enabled = (ctx%size > 1_i32) #endif ! 非MPIビルド時、または MPI 実行系が 1 rank としか見えていない場合でも、 ! launcher 環境変数から rank/size を補完して root 専用ログの重複を避ける。 if (ctx%size <= 1_i32) call infer_launcher_rank_size(ctx) end subroutine mpi_initialize