Skip to content
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

64 simple mpi support #65

Merged
merged 21 commits into from
Feb 12, 2024
Merged

64 simple mpi support #65

merged 21 commits into from
Feb 12, 2024

Conversation

hiker
Copy link
Collaborator

@hiker hiker commented Feb 24, 2022

This PR adds very simple (and not particularly efficient) MPI support:

  1. The constructor of fields takes an optional argument which is the global array (on each PE). Each PE then copies the data from its own subdomain into the field. That requires that the global array is created on each PE (instead of doing it on one PE, and then broadcasting the data), but it works really well with my example for the PSyclone training. The advantage of providing the global array on each PE is that there is no need during input handling to test if (on_master()), it is simply:
    allocate(initial_state(n_cols, n_rows))

    call get_initial_state(initial_state, n_rows, n_cols)

    initial = r2d_field(grid, grid_points = GO_T_POINTS,   &
                        init_global_data = initial_state)
  1. There is a new function to 'gather' a distributed array back into a 2d field. The output function still needs a if(on_master()), (so that only one process outputs the results)

@hiker
Copy link
Collaborator Author

hiker commented Feb 24, 2022

Maybe an example how output now works:

        call field%gather_inner_data(global_data)

        if (on_master()) then
            do j=lbound(global_data, 2), ubound(global_data, 2)
                write(*,"(99F2.0)") global_data(1:ubound(global_data,1), j)
            enddo
            write(*,*)
        endif
        deallocate(global_data)

@hiker
Copy link
Collaborator Author

hiker commented Feb 25, 2022

Ready for a first review. I am happy to discuss if this approach should be too limited (admittedly it was tweaked to simplify the PSyclone training).

hiker added 2 commits August 21, 2023 21:32
…o, which can result in mpi and non-mpi object files mixed in a non-mpi library).
@hiker
Copy link
Collaborator Author

hiker commented Jan 4, 2024

@arporter Hi Andy, would it be possible to get this reviewed in the near future? I am working on the PSyclone training, and atm I have to point to an external dl_esm_info repo (instead of the internal PSyclone one), and have to take care when compiling any psydata lib to also point to the same external repo (otherwise I get linking problems due to the additional functions).
And esp., if you don't like this approach, I need to redo my hands-on session.

Copy link
Member

@arporter arporter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for forgetting about this Joerg. Generally I think it looks good although I have to admit it feels like a bit of a retrograde step to allow global arrays (I think we used to have them and then I removed them). However, since you've made them optional then I think it's OK as long as we're clear that the library can be used without them. (This is important if we want a simple benchmark capable of running with a very large domain.)
Please could you add a test of the new reduction functionality under finite_difference/tests/dist_mem. Apart from that, there's only a couple of minor things.

doc/api.rst Show resolved Hide resolved
finite_difference/src/grid_mod.f90 Show resolved Hide resolved
doc/api.rst Show resolved Hide resolved
finite_difference/src/field_mod.f90 Outdated Show resolved Hide resolved
finite_difference/src/field_mod.f90 Outdated Show resolved Hide resolved
@hiker
Copy link
Collaborator Author

hiker commented Jan 8, 2024

Fixed, but am happy to discuss the requirement of the tmask in the telco tonight.

@hiker
Copy link
Collaborator Author

hiker commented Jan 9, 2024

I grep'ed for t_mask in the source files, and there seems to be no other use of the tmask, except for copying it in the grid constructor (it is passed as a parameter somewhere, but then not actually used). So I don't see a good reason to insist on having a tmask, since all of the code should be working just fine if there is no tmask.

Copy link
Member

@arporter arporter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the tests - they're nice :-)
After much thought and examination of PSycloneBench, I've concluded that we do need the T-mask so have requested you revert some of those changes.
If you agree then once that's done this is ready to go.

doc/api.rst Show resolved Hide resolved
doc/api.rst Outdated Show resolved Hide resolved
finite_difference/src/field_mod.f90 Show resolved Hide resolved
finite_difference/src/grid_mod.f90 Outdated Show resolved Hide resolved
finite_difference/src/grid_mod.f90 Outdated Show resolved Hide resolved
finite_difference/src/grid_mod.f90 Show resolved Hide resolved
finite_difference/tests/dist_mem/test_reduction.f90 Outdated Show resolved Hide resolved
finite_difference/tests/dist_mem/test_reduction.f90 Outdated Show resolved Hide resolved
finite_difference/tests/dist_mem/test_reduction.f90 Outdated Show resolved Hide resolved
@hiker
Copy link
Collaborator Author

hiker commented Jan 29, 2024

finite_difference/src/grid_mod.f90
call gocean_stop('grid_init: ERROR: No T-mask supplied and '// &
'grid does not have periodic boundary conditions!')
end if
!> TODO add support for PBCs in parallel
Member
@arporter arporter 3 days ago
I'd still like to keep the consistency check - an error message is always helpful :-)

Sorry, I don't know how to quote-reply to that comment, I don't have the usual 'reply' option.

As far as I can see, the state if we don't have a T-mask is either:

  1. We have periodic boundary conditions. Then indeed you don't need to supply a tmask ... but MPI execution aborts later(!) at a halo exchange since this is not yet supported.
  2. We don't have periodic boundary conditions. The above test will then abort the execution as well.

Given that 2. actually works, shouldn't it be the other way round? We abort early if we detect an unsupported configuration (instead of running and aborting later)?

I'll try to have a chat with you about this tonight. I feel we might have a misunderstanding. My change only makes the T-mask truly optional, all existing code that uses a T-mask will continue to work, but in addition we can also use it without T-mask, which we can't atm. The only configuration that would be a problem is if an application does not provide a tmask, but in a kernel then asks for it (though we could detect this and then either provide with an error, or even provide a dummy tmask, i.e. same size as the grid, filled with 1's)

@hiker
Copy link
Collaborator Author

hiker commented Jan 29, 2024

Hmm - I found a comment 'Please update the date.' for grid_mod.f90 ... since it had no license, I've added the usual license to the top of the file. But when trying to comment on that in the review here, it turns out that comment was for field_mod (which I had already fixed). Given that it seems correct to add a proper license for grid_mod, I left it in.

@hiker
Copy link
Collaborator Author

hiker commented Jan 31, 2024

I think I have updated everything as discussed. Back to you :)

Copy link
Member

@arporter arporter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good now - thanks.
I've checked the make_gen target of PSycloneBench with this branch and it was fine.
The tests added in this PR also work fine.
Will proceed to merge.

@arporter arporter merged commit e9c24f9 into master Feb 12, 2024
1 check passed
@arporter arporter deleted the 64_simple_mpi_support branch February 12, 2024 12:13
@arporter arporter mentioned this pull request Feb 12, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants