| 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 "LB_comm/shmem_mngo.h" | ||
| 21 | #include "LB_core/DLB_kernel.h" | ||
| 22 | #include "LB_core/spd.h" | ||
| 23 | #include "dlb_errors.h" | ||
| 24 | #include "mngo/mngo.h" | ||
| 25 | #include "mngo/mngo_resources.h" | ||
| 26 | #include "support/mask_utils.h" | ||
| 27 | #include "talp/talp_mpi.h" | ||
| 28 | #include "test_process.h" | ||
| 29 | #include "unique_shmem.h" | ||
| 30 | #include <assert.h> | ||
| 31 | #include <stdio.h> | ||
| 32 | #include <stdlib.h> | ||
| 33 | #include <string.h> | ||
| 34 | #include <sys/wait.h> | ||
| 35 | |||
| 36 | /* TLS global variable to store the spd pointer */ | ||
| 37 | extern __thread subprocess_descriptor_t *thread_spd; | ||
| 38 | |||
| 39 | static char options[128]; | ||
| 40 | |||
| 41 | 6 | cpu_set_t* get_mask_from_str(const char *mask) { | |
| 42 | 6 | cpu_set_t *mask_ptr = calloc(1, sizeof(cpu_set_t)); | |
| 43 | 6 | mu_parse_mask(mask, mask_ptr); | |
| 44 | 6 | return mask_ptr; | |
| 45 | } | ||
| 46 | |||
| 47 | 4 | void initialize(size_t id, const char *mask, subprocess_descriptor_t *spd) { | |
| 48 | enum { SHMEM_SIZE_MULTIPLIER = 1 }; | ||
| 49 | |||
| 50 | 4 | cpu_set_t *process_mask = get_mask_from_str(mask); | |
| 51 | |||
| 52 | 4 | spd->id = id; | |
| 53 | 4 | thread_spd = spd; | |
| 54 | |||
| 55 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert(Initialize(spd, id, 2, process_mask, options) == DLB_SUCCESS); |
| 56 | 4 | mngo_init(spd); | |
| 57 | |||
| 58 | 4 | free(process_mask); | |
| 59 | |||
| 60 | 4 | usleep(500); // Allow some time for the other processes to initialize their memory | |
| 61 | 4 | } | |
| 62 | |||
| 63 | 4 | void finalize(subprocess_descriptor_t *spd) { | |
| 64 | 4 | mngo_fini(spd); | |
| 65 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert(Finish(spd) == DLB_SUCCESS); |
| 66 | 4 | } | |
| 67 | |||
| 68 | 4 | void test__mngo(pid_t id, const char* mask, size_t load) { | |
| 69 | |||
| 70 | subprocess_descriptor_t spd; | ||
| 71 | 4 | initialize(id, mask, &spd); | |
| 72 | 4 | talp_mpi_init(&spd); | |
| 73 | |||
| 74 | { | ||
| 75 | 4 | dlb_mngo_region_t *region = mngo_region_register(&spd, "test"); | |
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | assert(region != NULL); |
| 77 | } | ||
| 78 | |||
| 79 | 4 | mngo_info_t *mngo_info = spd.mngo_info; | |
| 80 | 4 | queue_iter_head2tail_t iter = queue__into_head2tail_iter(mngo_info->region_handler.regions); | |
| 81 | 4 | dlb_mngo_region_t **monitor_from_queue = queue_iter__get_nth(&iter, 0); | |
| 82 | |||
| 83 | |||
| 84 | 4 | dlb_mngo_region_t *region = mngo_region_register(&spd, "test"); | |
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | assert(region->region_info.talp.monitor == (*monitor_from_queue)->region_info.talp.monitor); |
| 86 | |||
| 87 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | assert(mngo_region_start(&spd, region) == DLB_SUCCESS |
| 88 | && "Expected to close the region normally, before imbalanced load"); | ||
| 89 | 4 | usleep(load * 1000); | |
| 90 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | assert(mngo_region_stop(&spd, region) == DLB_SUCCESS |
| 91 | && "Expected to close the region normally, after imbalanced load"); | ||
| 92 | |||
| 93 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (spd.options.drom) { |
| 94 | // For now: DROM takes preference, so if drom and lewi are enabled we sould see some change | ||
| 95 | // in DROM | ||
| 96 | |||
| 97 | 2 | cpu_set_t *original_mask = get_mask_from_str(mask); | |
| 98 | // Check that the mask has changed | ||
| 99 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert(memcmp(®ion->region_info.state.drom_mask, original_mask, sizeof(cpu_set_t)) != 0); |
| 100 | 2 | free(original_mask); | |
| 101 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (spd.options.lewi) { |
| 102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert(region->region_info.state.lewi_on |
| 103 | && "lewi should be ON after load imbalance detected"); | ||
| 104 | } | ||
| 105 | |||
| 106 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | assert(mngo_region_start(&spd, region) == DLB_SUCCESS |
| 107 | && "Expected to start the region normally, before balanced load"); | ||
| 108 | 4 | usleep(400 * 1000); | |
| 109 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | assert(mngo_region_stop(&spd, region) == DLB_SUCCESS |
| 110 | && "Expected to close the region normally, after balanced load"); | ||
| 111 | |||
| 112 | { | ||
| 113 | 4 | dlb_mngo_region_t *region_not_top = mngo_region_register(&spd, "test-not-top"); | |
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | assert(region != NULL); |
| 115 | |||
| 116 | // Test close not open region | ||
| 117 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | assert(mngo_region_stop(&spd, region_not_top) == DLB_NOUPDT |
| 118 | && "Expected the region to not be open"); | ||
| 119 | |||
| 120 | // Test open already open region | ||
| 121 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | assert(mngo_region_start(&spd, region_not_top) == DLB_SUCCESS |
| 122 | && "Expected the region to not be open"); | ||
| 123 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | assert(mngo_region_start(&spd, region_not_top) == DLB_NOUPDT |
| 124 | && "Expected the region to be already open"); | ||
| 125 | |||
| 126 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | assert(mngo_region_stop(&spd, region_not_top) == DLB_SUCCESS |
| 127 | && "Expected to close the region normally as its open"); | ||
| 128 | } | ||
| 129 | |||
| 130 | 4 | talp_mpi_finalize(&spd); | |
| 131 | 4 | finalize(&spd); | |
| 132 | 4 | } | |
| 133 | |||
| 134 | 1 | int main(int argc, char *argv[]) { | |
| 135 | enum { SYS_SIZE = 128 }; | ||
| 136 | 1 | mu_testing_set_sys_size(SYS_SIZE); | |
| 137 | |||
| 138 | // Test mngo regions with DROM | ||
| 139 | 1 | strcpy(options, "--mngo --mngo-mode=regions --talp --drom --verbose=mngo --shm-key="); | |
| 140 | 1 | strcat(options, SHMEM_KEY); | |
| 141 | 1 | test_shmem_mngo__modify_barrier_participants(2); | |
| 142 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo(1, "0-63", 1)); |
| 143 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo(2, "64-127", 200)); |
| 144 |
4/6✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 1 times.
|
3 | WAITALL; |
| 145 | |||
| 146 | // Test mngo regions with LeWI | ||
| 147 | 1 | strcpy(options, "--mngo --mngo-mode=regions --talp --lewi --verbose=mngo --shm-key="); | |
| 148 | 1 | strcat(options, SHMEM_KEY); | |
| 149 | 1 | test_shmem_mngo__modify_barrier_participants(2); | |
| 150 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo(1, "0-63", 1)); |
| 151 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
1 | FORK(test__mngo(2, "64-127", 200)); |
| 152 |
4/6✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 1 times.
|
3 | WAITALL; |
| 153 | |||
| 154 | 1 | return 0; | |
| 155 | } | ||
| 156 |