(git:5e7fe52)
Loading...
Searching...
No Matches
message_passing_thread_unittest.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Exercises point-to-point MPI wrappers concurrently from multiple OpenMP threads.
10! **************************************************************************************************
12 USE omp_lib, ONLY: omp_get_num_threads,&
13 omp_get_thread_num,&
14 omp_set_dynamic,&
15 omp_set_num_threads
20 USE timings, ONLY: add_timer_env,&
23#include "../base/base_uses.f90"
24
25 IMPLICIT NONE
26
27 TYPE(mp_comm_type) :: world
28
29 CALL mp_world_init(world)
30
32 CALL add_timer_env()
33 mp_collect_timings = .true.
34
35 CALL omp_set_dynamic(.false.)
36 CALL omp_set_num_threads(2)
37!$OMP PARALLEL DEFAULT(NONE) SHARED(world)
39!$OMP END PARALLEL
40
41 mp_collect_timings = .false.
42 CALL rm_timer_env()
44
45CONTAINS
46
47! **************************************************************************************************
48!> \brief Exercise concurrent point-to-point communication on a shared communicator.
49!> \param comm communicator shared by all OpenMP threads
50! **************************************************************************************************
52 TYPE(mp_comm_type), INTENT(IN) :: comm
53
54 INTEGER, PARAMETER :: num_iterations = 128
55
56 INTEGER :: dest, expected, iter, nthreads, &
57 recv_value, send_value, source, tag, &
58 thread_id
59
60 thread_id = omp_get_thread_num()
61 nthreads = omp_get_num_threads()
62 cpassert(nthreads == 2)
63 cpassert(thread_id >= 0 .AND. thread_id < nthreads)
64
65 dest = modulo(comm%mepos + 1, comm%num_pe)
66 source = modulo(comm%mepos - 1, comm%num_pe)
67
68 DO iter = 1, num_iterations
69 tag = (iter - 1)*nthreads + thread_id
70 send_value = (comm%num_pe*(iter - 1) + comm%mepos)*nthreads + thread_id
71 CALL comm%sendrecv(send_value, dest, recv_value, source, tag=tag)
72 expected = (comm%num_pe*(iter - 1) + source)*nthreads + thread_id
73 cpassert(recv_value == expected)
74 END DO
76
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
program message_passing_thread_unittest
Exercises point-to-point MPI wrappers concurrently from multiple OpenMP threads.
subroutine exercise_concurrent_point_to_point(comm)
Exercise concurrent point-to-point communication on a shared communicator.
Interface to the message passing library MPI.
logical, save, public mp_collect_timings
subroutine, public mp_world_init(mp_comm)
initializes the system default communicator
subroutine, public mp_world_finalize()
Finalize the system default communicator and MPI when CP2K owns MPI.
Timing routines for accounting.
Definition timings.F:17
subroutine, public timings_register_hooks()
Registers handlers with base_hooks.F.
Definition timings.F:79
subroutine, public add_timer_env(timer_env)
adds the given timer_env to the top of the stack
Definition timings.F:93
subroutine, public rm_timer_env()
removes the current timer env from the stack
Definition timings.F:135