-
Notifications
You must be signed in to change notification settings - Fork 47
MPI Split communicator. #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mo-joshuacolclough
wants to merge
27
commits into
ecmwf-ifs:develop
Choose a base branch
from
mo-joshuacolclough:feature/custom_comm
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ae88a4d
Add dummy tests
mo-joshuacolclough 28774d7
Remove MPL_SET_DEFAULT_COMM and set default prior to MPL_INIT call
mo-joshuacolclough 281b875
Implement set_mpi_comm. Add transi example with split communicator
mo-joshuacolclough ae81b10
Add mpi includes in CMake
mo-joshuacolclough 2dc9ebb
Fix test include
mo-joshuacolclough 1947405
Check that if set_mpi_comm is called again, that it is with the same …
mo-joshuacolclough 4a0d487
Ensure logic is correct - only do check if MPL_INIT is called
mo-joshuacolclough 277053a
add MPI to libs
mo-joshuacolclough 306292b
Rename test example
mo-joshuacolclough 9fa3834
Comment on global grid point field
mo-joshuacolclough 793b622
update cmake
mo-joshuacolclough 4ecb953
Tidying
mo-joshuacolclough 9ef8c2c
Remove include <mpi.h>
mo-joshuacolclough 900cbbe
Only import what is used from mpl_data_module
mo-joshuacolclough 8cbdbc4
Comments
mo-joshuacolclough 1fb1f42
Revert transi CMakeLists
mo-joshuacolclough 3e18627
Link mpi to cmake test.
mo-joshuacolclough 5bf579f
Merge develop
mo-joshuacolclough 63111d0
Remove multiple_res test (saved in a separate branch). Get world size
mo-joshuacolclough 892a1cd
Add simple transi split comm test
mo-joshuacolclough 06499d4
Remove transi test_example (was copied from another test)
mo-joshuacolclough b9f0200
Remove unecessary imports in transi_module.F90
mo-joshuacolclough e917db1
Use MPL gather routines
mo-joshuacolclough d99f9ac
Tidy imports in test
mo-joshuacolclough 0e68acf
Use MPL for splitting of communicator following Sam's comments.
mo-joshuacolclough c189a68
Temporarily disable transi test
mo-joshuacolclough a99282d
Fix cmake
mo-joshuacolclough File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mo-joshuacolclough marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mo-joshuacolclough marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| ! (C) Crown Copyright 2025- Met Office. | ||
| ! | ||
| ! This software is licensed under the terms of the Apache Licence Version 2.0 | ||
| ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
| ! | ||
|
|
||
| program test_example | ||
mo-joshuacolclough marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| USE PARKIND1, ONLY: JPRM, JPIM | ||
| USE MPL_MODULE ,ONLY : MPL_INIT, MPL_END, MPL_BARRIER, MPL_MYRANK, MPL_NPROC, & | ||
| MPL_COMM_SPLIT | ||
| USE ABORT_TRANS_MOD, ONLY : ABORT_TRANS | ||
| use mpl_data_module | ||
| use mpl_mpif | ||
|
|
||
| implicit none | ||
|
|
||
| #include "setup_trans0.h" | ||
| #include "setup_trans.h" | ||
| #include "inv_trans.h" | ||
| #include "dir_trans.h" | ||
| #include "trans_inq.h" | ||
|
|
||
| integer(kind=JPIM), parameter, dimension(2) :: truncations = [79, 188] | ||
|
|
||
| ! MODE | ||
| integer(kind=JPIM), parameter, dimension(2) :: Ms = [1, 3] | ||
| integer(kind=JPIM), parameter, dimension(2) :: Ns = [2, 4] | ||
|
|
||
|
|
||
| integer(kind=JPIM) :: num_spectral_elements, num_grid_points | ||
| integer(kind=JPIM) :: g_num_spectral_elements, g_num_grid_points ! global | ||
| integer(kind=JPIM) :: mode_index | ||
mo-joshuacolclough marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| integer(kind=JPIM) :: ierror | ||
| integer(kind=JPIM) :: i | ||
| integer(kind=JPIM) :: num_ranks, rank | ||
| integer(kind=JPIM) :: split_colour, split_key | ||
| integer(kind=JPIM) :: split_comm | ||
| integer(kind=JPIM) :: truncation | ||
| integer(kind=JPIM) :: M, N | ||
| integer(kind=JPIM) :: num_latitudes, num_longitudes | ||
|
|
||
| ! Number of grid points on each rank | ||
| integer(kind=JPIM) :: grid_partition_size_local(1) | ||
| integer(kind=JPIM), allocatable :: displs(:) | ||
| integer(kind=JPIM), allocatable :: grid_partition_sizes(:) | ||
|
|
||
| integer(kind=JPIM), allocatable :: spectral_indices(:) | ||
|
|
||
| real(kind=JPRM), allocatable :: spectral_field(:,:) | ||
| real(kind=JPRM), allocatable :: grid_point_field(:,:,:) | ||
|
|
||
| real(kind=JPRM), allocatable :: g_grid_point_field(:) | ||
mo-joshuacolclough marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| character(len=1024) :: filename | ||
|
|
||
|
|
||
| call MPI_Init(ierror) | ||
| call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror) | ||
|
|
||
| split_colour = get_split_group() | ||
| split_key = rank | ||
mo-joshuacolclough marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| call MPI_Comm_split(MPI_COMM_WORLD, split_colour, split_key, split_comm, ierror) | ||
|
|
||
| print*, "=== Rank ", rank, ", Setup on group", split_colour, "===" | ||
|
|
||
| ! Set MPL comm | ||
| LMPLUSERCOMM = .true. | ||
mo-joshuacolclough marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| MPLUSERCOMM = split_comm | ||
| call MPL_INIT() | ||
|
|
||
|
|
||
| rank = MPL_MYRANK() | ||
mo-joshuacolclough marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| num_ranks = MPL_NPROC() | ||
mo-joshuacolclough marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print*, "=== Local rank ", rank, ", on group", split_colour, "size", num_ranks, "===" | ||
|
|
||
| ! Split grid NS Split spectral | ||
| call setup_trans0(KPRINTLEV=0, LDMPOFF=.false., KPRGPNS=num_ranks, KPRTRW=num_ranks) | ||
|
|
||
| ! DIFFERENT TRANSFORM BASED ON COMM GROUP | ||
| truncation = truncations(split_colour + 1) | ||
| print*, "TRUNCATION = ", truncation | ||
|
|
||
| num_latitudes = 2*(truncation + 1) | ||
| num_longitudes = num_latitudes*2 | ||
| print*, ">>> GLOBAL NUM LON =>", num_longitudes, "| LAT =>", num_latitudes | ||
| call setup_trans(KSMAX=truncation, KDGL=num_latitudes) | ||
|
|
||
| ! Get function space sizes | ||
| call trans_inq(KSPEC2=num_spectral_elements, KGPTOT=num_grid_points) | ||
| call trans_inq(KSPEC2G=g_num_spectral_elements, KGPTOTG=g_num_grid_points) | ||
| print*,"Num spec = ", num_spectral_elements, "| Num grid points = ", num_grid_points, g_num_grid_points | ||
mo-joshuacolclough marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| allocate(spectral_field(1, num_spectral_elements)) | ||
| allocate(grid_point_field(num_grid_points, 1, 1)) | ||
|
|
||
| ! Get spectral indices | ||
| allocate(spectral_indices(0:truncation)) | ||
| call trans_inq(KASM0=spectral_indices) | ||
|
|
||
| ! select mode | ||
| M = Ms(split_colour + 1) | ||
| N = Ns(split_colour + 1) | ||
| mode_index = spectral_indices(M) + 2*(N - M) + 1 | ||
|
|
||
| spectral_field(:,:) = 0.0 | ||
|
|
||
| if (mode_index > 0) then | ||
| spectral_field(1,mode_index) = 1.0 | ||
| end if | ||
|
|
||
| call inv_trans(PSPSCALAR=spectral_field, PGP=grid_point_field) | ||
|
|
||
| ! -------------- Gather the result on the root (0) and write to file ----------------- | ||
|
|
||
| ! Get counts from each PE. | ||
| grid_partition_size_local(1) = num_grid_points | ||
| allocate(grid_partition_sizes(num_ranks)) | ||
| grid_partition_sizes = 0 | ||
|
|
||
| call MPI_Gather(grid_partition_size_local, 1, MPI_INT, & | ||
| grid_partition_sizes, 1, MPI_INT, & | ||
| 0, split_comm, ierror) | ||
| if (ierror /= 0) then | ||
| print*,"MPI ERROR => ", ierror | ||
| call ABORT_TRANS("MPI ERROR") | ||
| end if | ||
|
|
||
| print*, "SIZES => ", grid_partition_sizes(:) | ||
|
|
||
| ! Allocate a global field. | ||
| allocate(g_grid_point_field(g_num_grid_points)) | ||
|
|
||
| ! Make displacement arrays | ||
| allocate(displs(num_ranks)) | ||
| displs = 0 | ||
| do i=2, num_ranks | ||
| displs(i) = displs(i - 1) + grid_partition_sizes(i - 1) | ||
| end do | ||
| print*,"displs => ", displs(:) | ||
|
|
||
mo-joshuacolclough marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| call MPI_Gatherv(grid_point_field(:,1,1), num_grid_points, MPI_FLOAT, & | ||
| g_grid_point_field, grid_partition_sizes, displs, MPI_FLOAT, & | ||
| 0, split_comm, ierror) | ||
| if (ierror /= 0) then | ||
| print*,"Gatherv MPI ERROR => ", ierror | ||
| call ABORT_TRANS("MPI ERROR") | ||
| end if | ||
|
|
||
| if (rank == 1) then | ||
| write(filename, "(A22,I0,A4)") "grid_point_field_group", split_colour, ".dat" | ||
| open(7, file=filename, form="unformatted") | ||
| write(7) g_grid_point_field(:) | ||
| close(7) | ||
| end if | ||
|
|
||
| call MPL_END() | ||
| call MPI_Finalize() | ||
|
|
||
| CONTAINS | ||
|
|
||
| ! Get the colour of comm for this rank. | ||
| function get_split_group() result(group) | ||
| implicit none | ||
| ! return | ||
| integer(kind=JPIM) :: group | ||
|
|
||
| integer(kind=JPIM) :: rank, world_size, ierror | ||
| real(kind=JPRM) :: rank_ratio | ||
|
|
||
| call MPI_Comm_size(MPI_COMM_WORLD, world_size, ierror) | ||
| call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror) | ||
|
|
||
| !group = mod(rank, 2) ! Split comm in half, alternating. | ||
|
|
||
| ! ---------------------------------------------- | ||
| ! Uneven splitting. | ||
| ! ---------------------------------------------- | ||
| rank_ratio = real(rank, kind=JPRM) / real(world_size, kind=JPRM) | ||
|
|
||
| ! Split X% | ||
| if (rank_ratio < 0.3_jprm) then | ||
| group = 0 | ||
| else | ||
| group = 1 | ||
| end if | ||
|
|
||
| end function get_split_group | ||
|
|
||
| end program | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.