| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2022 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_comm/shmem_barrier.h" | ||
| 23 | #include "LB_comm/shmem.h" | ||
| 24 | #include "LB_core/spd.h" | ||
| 25 | #include "support/mask_utils.h" | ||
| 26 | #include "support/options.h" | ||
| 27 | #include "support/debug.h" | ||
| 28 | #include "apis/dlb_errors.h" | ||
| 29 | #include "apis/dlb_types.h" | ||
| 30 | |||
| 31 | #include <assert.h> | ||
| 32 | #include <unistd.h> | ||
| 33 | #include <stdio.h> | ||
| 34 | #include <sys/types.h> | ||
| 35 | #include <sys/wait.h> | ||
| 36 | |||
| 37 | |||
| 38 | /* Test node barrier */ | ||
| 39 | |||
| 40 | struct data { | ||
| 41 | pthread_barrier_t barrier; | ||
| 42 | }; | ||
| 43 | |||
| 44 | 1 | int main(int argc, char **argv) { | |
| 45 | |||
| 46 | enum { SHMEM_SIZE_MULTIPLIER = 1 }; | ||
| 47 | |||
| 48 | /* Test multiple barriers with one process */ | ||
| 49 | { | ||
| 50 | options_t options; | ||
| 51 | 1 | options_init(&options, NULL); | |
| 52 | 1 | debug_init(&options); | |
| 53 | 1 | spd_enter_dlb(NULL); | |
| 54 | 1 | thread_spd->id = getpid(); | |
| 55 | |||
| 56 | 1 | printf("Testing multiple barriers with one process\n"); | |
| 57 | |||
| 58 | 1 | shmem_barrier__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER); | |
| 59 | 1 | int max_barriers = shmem_barrier__get_max_barriers(); | |
| 60 | 1 | barrier_t *barrier0 = shmem_barrier__register("Barrier 0", DLB_BARRIER_LEWI_OFF); | |
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( barrier0 != NULL ); |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (max_barriers > 2) { |
| 63 | ✗ | barrier_t *barrier1 = shmem_barrier__register("Barrier 1", DLB_BARRIER_LEWI_OFF); | |
| 64 | ✗ | assert( barrier1 != NULL ); | |
| 65 | ✗ | barrier_t *barrier2 = shmem_barrier__register("Barrier 2", DLB_BARRIER_LEWI_ON); | |
| 66 | ✗ | assert( barrier2 != NULL ); | |
| 67 | ✗ | barrier_t *barrier3 = shmem_barrier__register("Barrier 2", DLB_BARRIER_LEWI_ON); | |
| 68 | ✗ | assert( barrier2 == barrier3 ); | |
| 69 | ✗ | assert( shmem_barrier__detach(barrier3) == 1 ); | |
| 70 | |||
| 71 | ✗ | assert( shmem_barrier__attach(barrier2) == 2 ); | |
| 72 | ✗ | assert( shmem_barrier__attach(barrier2) == 3 ); | |
| 73 | ✗ | assert( shmem_barrier__detach(barrier2) == 2 ); | |
| 74 | ✗ | assert( shmem_barrier__detach(barrier2) == 1 ); | |
| 75 | |||
| 76 | ✗ | assert( shmem_barrier__detach(barrier1) == 0 ); | |
| 77 | ✗ | assert( shmem_barrier__detach(barrier2) == 0 ); | |
| 78 | } | ||
| 79 | |||
| 80 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_barrier__detach(barrier0) == 0 ); |
| 81 | 1 | shmem_barrier__finalize(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER); | |
| 82 | } | ||
| 83 | |||
| 84 | /* Test multiple barriers with one process */ | ||
| 85 | { | ||
| 86 | options_t options; | ||
| 87 | 1 | options_init(&options, NULL); | |
| 88 | 1 | debug_init(&options); | |
| 89 | 1 | spd_enter_dlb(NULL); | |
| 90 | 1 | thread_spd->id = getpid(); | |
| 91 | 1 | shmem_barrier__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER); | |
| 92 | |||
| 93 | 1 | printf("Testing multiple barriers with one process\n"); | |
| 94 | 1 | uint16_t max_barriers = (uint16_t)shmem_barrier__get_max_barriers(); | |
| 95 | 1 | barrier_t **barrier_list = calloc(max_barriers+1, sizeof(barrier_t*)); | |
| 96 | char barrier_name[16]; | ||
| 97 | 1 | bool lewi = false; | |
| 98 | |||
| 99 | /* Register MAX+1 barriers (twice to check the detach actually frees up space) */ | ||
| 100 | int i, j; | ||
| 101 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (j=0; j<2; ++j) { |
| 102 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | for (i=0; i<max_barriers; ++i) { |
| 103 | 4 | snprintf(barrier_name, 16, "Barrier %6d", i); | |
| 104 | 4 | barrier_list[i] = shmem_barrier__register(barrier_name, lewi); | |
| 105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | assert( barrier_list[i] != NULL ); |
| 106 | } | ||
| 107 | 2 | snprintf(barrier_name, 16, "Doesn't fit"); | |
| 108 | 2 | barrier_list[i] = shmem_barrier__register(barrier_name, lewi); | |
| 109 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( barrier_list[i] == NULL ); |
| 110 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | for (i=0; i<max_barriers; ++i) { |
| 111 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert( shmem_barrier__detach(barrier_list[i]) == 0 ); |
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | 1 | shmem_barrier__finalize(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER); | |
| 116 | } | ||
| 117 | |||
| 118 | 1 | return EXIT_SUCCESS; | |
| 119 | } | ||
| 120 |