| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2026 Barcelona Supercomputing Center */ | ||
| 3 | /* */ | ||
| 4 | /* This file is part of the DLB library. */ | ||
| 5 | /* */ | ||
| 6 | /* DLB is free software: you can redistribute it and/or modify */ | ||
| 7 | /* it under the terms of the GNU Lesser General Public License as published by */ | ||
| 8 | /* the Free Software Foundation, either version 3 of the License, or */ | ||
| 9 | /* (at your option) any later version. */ | ||
| 10 | /* */ | ||
| 11 | /* DLB is distributed in the hope that it will be useful, */ | ||
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | ||
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | ||
| 14 | /* GNU Lesser General Public License for more details. */ | ||
| 15 | /* */ | ||
| 16 | /* You should have received a copy of the GNU Lesser General Public License */ | ||
| 17 | /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 18 | /*********************************************************************************/ | ||
| 19 | |||
| 20 | #include "unique_shmem.h" | ||
| 21 | |||
| 22 | #include "LB_core/DLB_kernel.h" | ||
| 23 | #include "LB_core/spd.h" | ||
| 24 | #include "LB_core/thread_ctx.h" | ||
| 25 | #include "LB_comm/shmem_talp.h" | ||
| 26 | #include "apis/dlb_talp.h" | ||
| 27 | #include "apis/dlb_errors.h" | ||
| 28 | #include "support/atomic.h" | ||
| 29 | #include "support/mytime.h" | ||
| 30 | #include "talp/regions.h" | ||
| 31 | #include "talp/sample.h" | ||
| 32 | #include "talp/talp.h" | ||
| 33 | #include "talp/talp_mpi.h" | ||
| 34 | #include "talp/talp_types.h" | ||
| 35 | |||
| 36 | #include <sched.h> | ||
| 37 | #include <stdint.h> | ||
| 38 | #include <string.h> | ||
| 39 | #include <assert.h> | ||
| 40 | |||
| 41 | /* Test Global Monitoring Regions with/without LeWI */ | ||
| 42 | |||
| 43 | enum { USLEEP_TIME = 100000 }; | ||
| 44 | |||
| 45 | 2 | int main(int argc, char *argv[]) { | |
| 46 | |||
| 47 | 2 | char options[64] = "--talp --talp-external-profiler --shm-key="; | |
| 48 | 2 | strcat(options, SHMEM_KEY); | |
| 49 | 2 | subprocess_descriptor_t spd = {.id = 111}; | |
| 50 | 2 | options_init(&spd.options, options); | |
| 51 | |||
| 52 | 2 | bool lewi = spd.options.lewi; | |
| 53 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (lewi) { |
| 54 | /* FIXME: This test is temporarily disabled with LeWI | ||
| 55 | * It needs to be rewritten once LeWI is supported again on TALP | ||
| 56 | */ | ||
| 57 | 1 | return 0; | |
| 58 | } | ||
| 59 | |||
| 60 | 1 | thread_ctx_set_main(THREAD_MAIN_SEQUENTIAL); | |
| 61 | 1 | talp_init(&spd); | |
| 62 | |||
| 63 | 1 | talp_info_t *talp_info = spd.talp_info; | |
| 64 | 1 | sample_registry_t *registry = &talp_info->sample_registry; | |
| 65 | 1 | dlb_monitor_t *global_monitor = talp_info->monitor; | |
| 66 | |||
| 67 | /* Disable external profiler for the following tests */ | ||
| 68 | 1 | talp_info->flags.external_profiler = false; | |
| 69 | |||
| 70 | /* Start global monitoring region */ | ||
| 71 | 1 | talp_mpi_init(&spd); | |
| 72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_measurements == 0 ); |
| 73 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_resets == 0 ); |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->start_time != 0 ); |
| 75 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->stop_time == 0 ); |
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->elapsed_time == 0 ); |
| 77 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->mpi_time == 0 ); |
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->useful_time == 0 ); |
| 79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->timers.useful == 0 ); |
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->timers.not_useful_mpi == 0 ); |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->state == TALP_STATE_USEFUL ); |
| 82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->num_samples == 1 ); |
| 83 | |||
| 84 | /* We are getting timestamps before and after talp_into_sync_call / talp_out_of_sync_call | ||
| 85 | * to check whether sample->last_updated_ts is updated. Equivalence | ||
| 86 | * is accepted because clock_gettime is allowed to return the same value on | ||
| 87 | * successive calls. */ | ||
| 88 | int64_t time_before; | ||
| 89 | int64_t time_after; | ||
| 90 | |||
| 91 | 1 | sync_call_flags_t no_blocking = { .is_blocking = false, .is_collective = false }; | |
| 92 | 1 | sync_call_flags_t blocking = { .is_blocking = true, .is_collective = true }; | |
| 93 | |||
| 94 | /* Entering MPI, sample is updated, region not yet */ | ||
| 95 | 1 | time_before = get_time_in_ns(); | |
| 96 | 1 | talp_into_sync_call(&spd, no_blocking); | |
| 97 | 1 | time_after = get_time_in_ns(); | |
| 98 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( registry->samples[0]->last_updated_ts >= time_before |
| 99 | && registry->samples[0]->last_updated_ts <= time_after ); | ||
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->timers.useful > 0 ); |
| 101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->timers.not_useful_mpi == 0 ); |
| 102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->state == TALP_STATE_NOT_USEFUL_MPI ); |
| 103 | |||
| 104 | /* Leaving MPI */ | ||
| 105 | 1 | time_before = get_time_in_ns(); | |
| 106 | 1 | talp_out_of_sync_call(&spd, no_blocking); | |
| 107 | 1 | time_after = get_time_in_ns(); | |
| 108 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | assert( registry->samples[0]->last_updated_ts >= time_before |
| 109 | && registry->samples[0]->last_updated_ts <= time_after ); | ||
| 110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->timers.useful > 0 ); |
| 111 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->timers.not_useful_mpi > 0 ); |
| 112 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( registry->samples[0]->state == TALP_STATE_USEFUL ); |
| 113 | |||
| 114 | /* Update regions */ | ||
| 115 | 1 | talp_sample_update(talp_info); | |
| 116 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( talp_aggregate_samples_to_regions(talp_info) == DLB_SUCCESS ); |
| 117 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->mpi_time > 0 ); |
| 118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->useful_time > 0 ); |
| 119 | |||
| 120 | /* Checking that the shmem has not been updated (--talp-external-profiler=no) */ | ||
| 121 | 1 | int64_t mpi_time = -1; | |
| 122 | 1 | int64_t useful_time = -1; | |
| 123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( talp_info->flags.external_profiler == false ); |
| 124 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__get_times(0, &mpi_time, &useful_time) == DLB_SUCCESS ); |
| 125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( mpi_time == 0 ); |
| 126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( useful_time == 0 ); |
| 127 | |||
| 128 | /* Enable --talp-external-profiler and test that the global region is updated */ | ||
| 129 | 1 | mpi_time = -1; | |
| 130 | 1 | useful_time = -1; | |
| 131 | 1 | talp_info->flags.external_profiler = true; | |
| 132 | 1 | talp_into_sync_call(&spd, blocking); | |
| 133 | 1 | talp_out_of_sync_call(&spd, blocking); | |
| 134 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__get_times(0, &mpi_time, &useful_time) == DLB_SUCCESS ); |
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( mpi_time > 0 ); |
| 136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( useful_time > 0 ); |
| 137 | |||
| 138 | /* Create a custom monitoring region */ | ||
| 139 | 1 | dlb_monitor_t *monitor = region_register(&spd, "Test"); | |
| 140 | 1 | region_start(&spd, monitor); | |
| 141 | 1 | talp_into_sync_call(&spd, no_blocking); | |
| 142 | 1 | talp_out_of_sync_call(&spd, no_blocking); | |
| 143 | 1 | region_stop(&spd, monitor); | |
| 144 | |||
| 145 | /* Finalize MPI */ | ||
| 146 | 1 | talp_mpi_finalize(&spd); | |
| 147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_measurements == 1 ); |
| 148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_resets == 0 ); |
| 149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->start_time != 0 ); |
| 150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->stop_time != 0 ); |
| 151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->elapsed_time |
| 152 | == global_monitor->stop_time - global_monitor->start_time ); | ||
| 153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->mpi_time != 0 ); |
| 154 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->useful_time != 0 ); |
| 155 | |||
| 156 | /* Checking that the shmem has now been updated */ | ||
| 157 | 1 | mpi_time = -1; | |
| 158 | 1 | useful_time = -1; | |
| 159 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__get_times(0, &mpi_time, &useful_time) == DLB_SUCCESS ); |
| 160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( mpi_time == global_monitor->mpi_time ); |
| 161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( useful_time == global_monitor->useful_time ); |
| 162 | |||
| 163 | 1 | spd.options.talp_summary |= SUMMARY_NODE; | |
| 164 | 1 | spd.options.talp_summary |= SUMMARY_PROCESS; | |
| 165 | 1 | talp_finalize(&spd); | |
| 166 | |||
| 167 | 1 | return 0; | |
| 168 | } | ||
| 169 |