| 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/spd.h" | ||
| 23 | #include "apis/dlb.h" | ||
| 24 | #include "apis/dlb_talp.h" | ||
| 25 | #include "support/mytime.h" | ||
| 26 | #include "talp/regions.h" | ||
| 27 | #include "talp/talp_mpi.h" | ||
| 28 | |||
| 29 | #include <sched.h> | ||
| 30 | #include <unistd.h> | ||
| 31 | #include <string.h> | ||
| 32 | #include <stdio.h> | ||
| 33 | #include <assert.h> | ||
| 34 | |||
| 35 | /* Test Monitoring Regions API */ | ||
| 36 | |||
| 37 | #include <time.h> | ||
| 38 | |||
| 39 | 1 | void wait_for_monotonic_clock_advance(void) | |
| 40 | { | ||
| 41 | struct timespec before; | ||
| 42 | struct timespec after; | ||
| 43 | |||
| 44 | 1 | clock_gettime(CLOCK_MONOTONIC, &before); | |
| 45 | |||
| 46 | do { | ||
| 47 | 1 | clock_gettime(CLOCK_MONOTONIC, &after); | |
| 48 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } while (after.tv_sec == before.tv_sec && |
| 49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | after.tv_nsec == before.tv_nsec); |
| 50 | 1 | } | |
| 51 | |||
| 52 | 1 | int main(int argc, char **argv) { | |
| 53 | cpu_set_t process_mask; | ||
| 54 | 1 | CPU_ZERO(&process_mask); | |
| 55 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CPU_SET(0, &process_mask); |
| 56 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CPU_SET(1, &process_mask); |
| 57 | |||
| 58 | /* Test DLB_ERR_NOTALP */ | ||
| 59 | { | ||
| 60 | 1 | char notalp_opts[64] = "--shm-key="; | |
| 61 | 1 | strcat(notalp_opts, SHMEM_KEY); | |
| 62 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, &process_mask, notalp_opts) == DLB_SUCCESS ); |
| 63 | 1 | dlb_monitor_t *monitor = DLB_MonitoringRegionRegister("Test monitor"); | |
| 64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor == NULL ); |
| 65 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(monitor) == DLB_ERR_NOTALP ); |
| 66 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(monitor) == DLB_ERR_NOTALP ); |
| 67 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionReset(monitor) == DLB_ERR_NOTALP ); |
| 68 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionReport(monitor) == DLB_ERR_NOTALP ); |
| 69 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 70 | } | ||
| 71 | |||
| 72 | /* Test with --talp enabled */ | ||
| 73 | { | ||
| 74 | 1 | char options[64] = "--talp --talp-summary=all --shm-key="; | |
| 75 | 1 | strcat(options, SHMEM_KEY); | |
| 76 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, &process_mask, options) == DLB_SUCCESS ); |
| 77 | |||
| 78 | char value[16]; | ||
| 79 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_GetVariable("--talp", value) == DLB_SUCCESS ); |
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( strcmp(value, "default") == 0 ); |
| 81 | |||
| 82 | 1 | dlb_monitor_t *monitor = DLB_MonitoringRegionRegister("Test monitor"); | |
| 83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor != NULL ); |
| 84 | |||
| 85 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(monitor) == DLB_SUCCESS ); |
| 86 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(monitor) == DLB_NOUPDT ); |
| 87 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(monitor) == DLB_SUCCESS ); |
| 88 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(monitor) == DLB_NOUPDT ); |
| 89 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionReset(monitor) == DLB_SUCCESS ); |
| 90 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionReport(monitor) == DLB_SUCCESS ); |
| 91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(monitor) == DLB_SUCCESS ); |
| 92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(monitor) == DLB_SUCCESS ); |
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( monitor->useful_time == monitor->elapsed_time ); |
| 94 | |||
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 96 | } | ||
| 97 | |||
| 98 | /* Test monitoring regions after MPI_Finalize */ | ||
| 99 | { | ||
| 100 | 1 | char options[64] = "--talp --shm-key="; | |
| 101 | 1 | strcat(options, SHMEM_KEY); | |
| 102 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, &process_mask, options) == DLB_SUCCESS ); |
| 103 | |||
| 104 | /* Check that global region has started */ | ||
| 105 | 1 | const dlb_monitor_t *global_monitor = DLB_MonitoringRegionGetGlobal(); | |
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor != NULL ); |
| 107 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_is_started(global_monitor) ); |
| 108 | |||
| 109 | /* A region named "Global" (case-insensitive) is equivalent to the global region */ | ||
| 110 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionRegister(DLB_GLOBAL_REGION_NAME) == global_monitor ); |
| 111 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionRegister("Global") == global_monitor ); |
| 112 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionRegister("global") == global_monitor ); |
| 113 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionRegister("GLOBAL") == global_monitor ); |
| 114 | |||
| 115 | /* Create custom monitor */ | ||
| 116 | 1 | dlb_monitor_t *custom_monitor = DLB_MonitoringRegionRegister("Custom monitor"); | |
| 117 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStart(custom_monitor) == DLB_SUCCESS ); |
| 118 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( region_is_started(custom_monitor) ); |
| 119 | |||
| 120 | /* Simulate MPI_Init + MPI_Barrier + MPI_Finalize */ | ||
| 121 | 1 | sync_call_flags_t blocking = { .is_mpi = true, .is_blocking = true, .is_collective = true }; | |
| 122 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Init(0, NULL, NULL) == DLB_ERR_INIT ); |
| 123 | 1 | talp_mpi_init(thread_spd); | |
| 124 | 1 | talp_into_sync_call(thread_spd, blocking); | |
| 125 | 1 | wait_for_monotonic_clock_advance(); | |
| 126 | 1 | talp_out_of_sync_call(thread_spd, blocking); | |
| 127 | 1 | talp_mpi_finalize(thread_spd); | |
| 128 | |||
| 129 | /* Global monitor should have been updated and started again */ | ||
| 130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_measurements == 1 ); |
| 131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->num_mpi_calls == 3 ); |
| 132 | // FIXME: the asserts below have failed a couple of times in ARM clusters. | ||
| 133 | // Adding error logs to try to figure out if it's just two | ||
| 134 | // consecutive clock_gettime returning the same value. | ||
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!(global_monitor->mpi_time > 0)) { |
| 136 | ✗ | fprintf(stderr, "MPI time check failed: %"PRId64"\n", global_monitor->mpi_time); | |
| 137 | } | ||
| 138 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!(global_monitor->useful_time > 0)) { |
| 139 | ✗ | fprintf(stderr, "Useful time check failed: %"PRId64"\n", global_monitor->useful_time); | |
| 140 | } | ||
| 141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->mpi_time > 0 ); |
| 142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( global_monitor->useful_time > 0 ); |
| 143 | // FIXME: to be addressed in issue #325 | ||
| 144 | /* assert( region_is_started(global_monitor) ); */ | ||
| 145 | |||
| 146 | /* Custom monitor should still be reachable too */ | ||
| 147 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_MonitoringRegionStop(custom_monitor) == DLB_SUCCESS ); |
| 148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( custom_monitor->num_measurements == 1 ); |
| 149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( custom_monitor->num_mpi_calls == 3 ); |
| 150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( custom_monitor->mpi_time > 0 ); |
| 151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( custom_monitor->useful_time > 0 ); |
| 152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( custom_monitor->elapsed_time > 0 ); |
| 153 | // FIXME: to be addressed in issue #325 | ||
| 154 | // they should not be equal, but just to avoid the clocktime giving the same time twice | ||
| 155 | /* assert( custom_monitor->elapsed_time <= global_monitor->elapsed_time ); */ | ||
| 156 | |||
| 157 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_Finalize() == DLB_SUCCESS ); |
| 158 | } | ||
| 159 | |||
| 160 | 1 | return 0; | |
| 161 | } | ||
| 162 |