| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2021 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 "assert_loop.h" | ||
| 21 | #include "unique_shmem.h" | ||
| 22 | |||
| 23 | #include "apis/dlb_errors.h" | ||
| 24 | #include "LB_core/spd.h" | ||
| 25 | #include "LB_policies/lewi.h" | ||
| 26 | #include "LB_numThreads/numThreads.h" | ||
| 27 | #include "support/options.h" | ||
| 28 | #include "support/debug.h" | ||
| 29 | |||
| 30 | #include <string.h> | ||
| 31 | |||
| 32 | static int nthreads; | ||
| 33 | |||
| 34 | 9 | static void cb_set_num_threads(int num_threads, void *arg) { | |
| 35 | 9 | nthreads = num_threads; | |
| 36 | 9 | } | |
| 37 | |||
| 38 | 1 | int main( int argc, char **argv ) { | |
| 39 | 1 | char options[64] = "--verbose=shmem --shm-key="; | |
| 40 | 1 | strcat(options, SHMEM_KEY); | |
| 41 | |||
| 42 | subprocess_descriptor_t spd; | ||
| 43 | 1 | spd.id = getpid(); | |
| 44 | 1 | options_init(&spd.options, options); | |
| 45 | 1 | debug_init(&spd.options); | |
| 46 | 1 | pm_init(&spd.pm); | |
| 47 | |||
| 48 | cpu_set_t process_mask; | ||
| 49 | 1 | sched_getaffinity(0, sizeof(cpu_set_t), &process_mask); | |
| 50 | 1 | spd.lewi_ncpus = CPU_COUNT(&process_mask); | |
| 51 | 1 | nthreads = spd.lewi_ncpus; | |
| 52 | 1 | int original_nthreads = nthreads; | |
| 53 | |||
| 54 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( pm_callback_set(&spd.pm, dlb_callback_set_num_threads, |
| 55 | (dlb_callback_t)cb_set_num_threads, NULL) == DLB_SUCCESS ); | ||
| 56 | |||
| 57 | // Init | ||
| 58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Init(&spd) == DLB_SUCCESS ); |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == original_nthreads ); |
| 60 | |||
| 61 | // Lend all CPUs minus 1 | ||
| 62 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Lend(&spd) == DLB_SUCCESS ); |
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == 1 ); |
| 64 | |||
| 65 | // Reclaim all | ||
| 66 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Reclaim(&spd) == DLB_SUCCESS ); |
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == original_nthreads ); |
| 68 | |||
| 69 | // Borrow can't obtain CPUs now | ||
| 70 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Borrow(&spd) == DLB_NOUPDT ); |
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == original_nthreads ); |
| 72 | |||
| 73 | // Lend | ||
| 74 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Lend(&spd) == DLB_SUCCESS ); |
| 75 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == 1 ); |
| 76 | |||
| 77 | // Borrow some CPUs | ||
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (original_nthreads >= 3) { |
| 79 | ✗ | assert( lewi_BorrowCpus(&spd, 2) == DLB_SUCCESS ); | |
| 80 | ✗ | assert( nthreads == 3 ); | |
| 81 | } | ||
| 82 | |||
| 83 | // Into MPI | ||
| 84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Reclaim(&spd) == DLB_SUCCESS ); |
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == original_nthreads ); |
| 86 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_IntoBlockingCall(&spd) == DLB_SUCCESS ); |
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == 1 ); |
| 88 | |||
| 89 | // Out of MPI | ||
| 90 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_OutOfBlockingCall(&spd) == DLB_SUCCESS ); |
| 91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == original_nthreads ); |
| 92 | |||
| 93 | // MaxParallelism test with Borrow | ||
| 94 | { | ||
| 95 | // Lend | ||
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Lend(&spd) == DLB_SUCCESS ); |
| 97 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == 1 ); |
| 98 | |||
| 99 | // Set MaxParallelism | ||
| 100 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_SetMaxParallelism(&spd, 4) == DLB_SUCCESS); |
| 101 | |||
| 102 | // Borrow | ||
| 103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (original_nthreads >= 4) { |
| 104 | ✗ | assert( lewi_Borrow(&spd) == DLB_SUCCESS ); | |
| 105 | ✗ | assert( nthreads == 4 ); | |
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | // MaxParallelism test with BorrowCpu | ||
| 110 | { | ||
| 111 | // Lend | ||
| 112 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Lend(&spd) == DLB_SUCCESS ); |
| 113 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == 1 ); |
| 114 | |||
| 115 | // Set MaxParallelism | ||
| 116 | enum { MAX_PARALLELISM_FACTOR = 4 }; | ||
| 117 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_SetMaxParallelism(&spd, MAX_PARALLELISM_FACTOR) == DLB_SUCCESS); |
| 118 | |||
| 119 | // BorrowCpus one by one | ||
| 120 | int i; | ||
| 121 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | for (i=2; i<=original_nthreads; ++i) { |
| 122 | 1 | int err = lewi_BorrowCpus(&spd, 1); | |
| 123 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (i<=MAX_PARALLELISM_FACTOR) { |
| 124 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( err == DLB_SUCCESS); |
| 125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( nthreads == i ); |
| 126 | } else { | ||
| 127 | ✗ | assert( err == DLB_NOUPDT); | |
| 128 | ✗ | assert( nthreads == MAX_PARALLELISM_FACTOR ); | |
| 129 | } | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | // Finalize | ||
| 134 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( lewi_Finalize(&spd) == DLB_SUCCESS ); |
| 135 | |||
| 136 | 1 | return 0; | |
| 137 | } | ||
| 138 |