| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2024 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 | // LeWI_async checks with 1 processes | ||
| 21 | |||
| 22 | #include "assert_loop.h" | ||
| 23 | #include "unique_shmem.h" | ||
| 24 | |||
| 25 | #include "LB_core/spd.h" | ||
| 26 | #include "LB_comm/shmem_async.h" | ||
| 27 | #include "LB_policies/lewi_async.h" | ||
| 28 | #include "apis/dlb_errors.h" | ||
| 29 | #include "support/mask_utils.h" | ||
| 30 | #include "support/debug.h" | ||
| 31 | |||
| 32 | #include <string.h> | ||
| 33 | |||
| 34 | static int num_threads; | ||
| 35 | 11 | void set_num_threads_callback(int nthreads, void *arg) { | |
| 36 | 11 | num_threads = nthreads; | |
| 37 | 11 | } | |
| 38 | |||
| 39 | 1 | int main(int argc, char *argv[]) { | |
| 40 | // This test needs at least room for 4 CPUs | ||
| 41 | enum { SYS_SIZE = 4 }; | ||
| 42 | 1 | mu_init(); | |
| 43 | 1 | mu_testing_set_sys_size(SYS_SIZE); | |
| 44 | |||
| 45 | 1 | int initial_num_threads = SYS_SIZE; | |
| 46 | 1 | num_threads = SYS_SIZE; | |
| 47 | |||
| 48 | // Options | ||
| 49 | 1 | char options[64] = "--shm-key="; | |
| 50 | 1 | strcat(options, SHMEM_KEY); | |
| 51 | 1 | fprintf(stderr, "%s\n", options); | |
| 52 | |||
| 53 | // Init | ||
| 54 | 1 | subprocess_descriptor_t spd = {.id = 111, .lewi_ncpus = SYS_SIZE}; | |
| 55 | 1 | mu_get_system_mask(&spd.process_mask); | |
| 56 | 1 | options_init(&spd.options, options); | |
| 57 | 1 | debug_init(&spd.options); | |
| 58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pm_callback_set(&spd.pm, dlb_callback_set_num_threads, |
| 59 | (dlb_callback_t)set_num_threads_callback, NULL) == DLB_SUCCESS); | ||
| 60 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_async_init(spd.id, &spd.pm, &spd.process_mask, |
| 61 | spd.options.shm_key, spd.options.shm_size_multiplier) == DLB_SUCCESS ); | ||
| 62 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Init(&spd) == DLB_SUCCESS ); |
| 63 | |||
| 64 | // Reclaim (this should not trigger a callback) | ||
| 65 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Reclaim(&spd) == DLB_NOUPDT ); |
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads ); |
| 67 | |||
| 68 | // Acquire 1 CPU | ||
| 69 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_AcquireCpus(&spd, 1) == DLB_NOTED ); |
| 70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads ); |
| 71 | |||
| 72 | // Remove request | ||
| 73 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_AcquireCpus(&spd, DLB_DELETE_REQUESTS) == DLB_SUCCESS ); |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads ); |
| 75 | |||
| 76 | // Lend 1 CPU | ||
| 77 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_LendCpus(&spd, 1) == DLB_SUCCESS ); |
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads - 1 ); |
| 79 | |||
| 80 | // Lend everything | ||
| 81 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Lend(&spd) == DLB_SUCCESS ); |
| 82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == 1 ); |
| 83 | |||
| 84 | // Borrow 1 CPU | ||
| 85 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_BorrowCpus(&spd, 1) == DLB_SUCCESS ); |
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == 2 ); |
| 87 | |||
| 88 | // Borrow | ||
| 89 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Borrow(&spd) == DLB_SUCCESS ); |
| 90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads ); |
| 91 | |||
| 92 | // Lend everything again and Reclaim | ||
| 93 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Lend(&spd) == DLB_SUCCESS ); |
| 94 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == 1 ); |
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Reclaim(&spd) == DLB_SUCCESS ); |
| 96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads ); |
| 97 | |||
| 98 | // IntoBlockingCall | ||
| 99 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_IntoBlockingCall(&spd) == DLB_SUCCESS ); |
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == 1 ); |
| 101 | |||
| 102 | // OutOfBlockingCall | ||
| 103 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_OutOfBlockingCall(&spd) == DLB_SUCCESS ); |
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads ); |
| 105 | |||
| 106 | // Disable | ||
| 107 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Disable(&spd) == DLB_SUCCESS ); |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads ); |
| 109 | |||
| 110 | // Enable | ||
| 111 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Enable(&spd) == DLB_SUCCESS ); |
| 112 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( num_threads == initial_num_threads ); |
| 113 | |||
| 114 | // Finalize | ||
| 115 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_async_Finalize(&spd) == DLB_SUCCESS ); |
| 116 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_async_finalize(spd.id) == DLB_SUCCESS ); |
| 117 | |||
| 118 | 1 | mu_finalize(); | |
| 119 | |||
| 120 | 1 | return 0; | |
| 121 | } | ||
| 122 |