ARGOBOTS  dce6e727ffc4ca5b3ffc04cb9517c6689be51ec5
barrier.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include "abti.h"
7 
47 int ABT_barrier_create(uint32_t num_waiters, ABT_barrier *newbarrier)
48 {
49  ABTI_UB_ASSERT(ABTI_initialized());
50  ABTI_UB_ASSERT(newbarrier);
51 
52 #ifndef ABT_CONFIG_ENABLE_VER_20_API
53  /* Argobots 1.x sets newbarrier to NULL on error. */
54  *newbarrier = ABT_BARRIER_NULL;
55 #endif
56  int abt_errno;
57  ABTI_barrier *p_newbarrier;
58  ABTI_CHECK_TRUE(num_waiters != 0, ABT_ERR_INV_ARG);
59  size_t arg_num_waiters = num_waiters;
60 
61  abt_errno = ABTU_malloc(sizeof(ABTI_barrier), (void **)&p_newbarrier);
62  ABTI_CHECK_ERROR(abt_errno);
63 
64  ABTD_spinlock_clear(&p_newbarrier->lock);
65  p_newbarrier->num_waiters = arg_num_waiters;
66  p_newbarrier->counter = 0;
67  ABTI_waitlist_init(&p_newbarrier->waitlist);
68  /* Return value */
69  *newbarrier = ABTI_barrier_get_handle(p_newbarrier);
70  return ABT_SUCCESS;
71 }
72 
102 int ABT_barrier_reinit(ABT_barrier barrier, uint32_t num_waiters)
103 {
104  ABTI_UB_ASSERT(ABTI_initialized());
105 
106  ABTI_barrier *p_barrier = ABTI_barrier_get_ptr(barrier);
107  ABTI_CHECK_NULL_BARRIER_PTR(p_barrier);
108  ABTI_UB_ASSERT(p_barrier->counter == 0);
109  ABTI_CHECK_TRUE(num_waiters != 0, ABT_ERR_INV_ARG);
110  size_t arg_num_waiters = num_waiters;
111 
112  /* Only when num_waiters is different from p_barrier->num_waiters, we
113  * change p_barrier. */
114  if (arg_num_waiters != p_barrier->num_waiters) {
115  /* We can reuse waiters and waiter_type arrays */
116  p_barrier->num_waiters = arg_num_waiters;
117  }
118  return ABT_SUCCESS;
119 }
120 
145 {
146  ABTI_UB_ASSERT(ABTI_initialized());
147  ABTI_UB_ASSERT(barrier);
148 
149  ABT_barrier h_barrier = *barrier;
150  ABTI_barrier *p_barrier = ABTI_barrier_get_ptr(h_barrier);
151  ABTI_CHECK_NULL_BARRIER_PTR(p_barrier);
152 
153  /* The lock needs to be acquired to safely free the barrier structure.
154  * However, we do not have to unlock it because the entire structure is
155  * freed here. */
156  ABTD_spinlock_acquire(&p_barrier->lock);
157 
158  /* p_barrier->counter must be checked after taking a lock. */
159  ABTI_UB_ASSERT(p_barrier->counter == 0);
160 
161  ABTU_free(p_barrier);
162 
163  /* Return value */
164  *barrier = ABT_BARRIER_NULL;
165  return ABT_SUCCESS;
166 }
167 
198 {
199  ABTI_UB_ASSERT(ABTI_initialized());
200 
201  ABTI_local *p_local = ABTI_local_get_local();
202  ABTI_barrier *p_barrier = ABTI_barrier_get_ptr(barrier);
203  ABTI_CHECK_NULL_BARRIER_PTR(p_barrier);
204 
205 #ifndef ABT_CONFIG_ENABLE_VER_20_API
206  /* Calling a barrier on a tasklet is not allowed. */
207  if (ABTI_IS_ERROR_CHECK_ENABLED && p_local) {
208  ABTI_xstream *p_local_xstream = ABTI_local_get_xstream(p_local);
209  ABTI_CHECK_TRUE(p_local_xstream->p_thread->type &
210  ABTI_THREAD_TYPE_YIELDABLE,
212  }
213 #endif
214 
215  ABTD_spinlock_acquire(&p_barrier->lock);
216 
217  ABTI_ASSERT(p_barrier->counter < p_barrier->num_waiters);
218  p_barrier->counter++;
219 
220  /* If we do not have all the waiters yet */
221  if (p_barrier->counter < p_barrier->num_waiters) {
222  ABTI_waitlist_wait_and_unlock(&p_local, &p_barrier->waitlist,
223  &p_barrier->lock,
225  (void *)p_barrier);
226  } else {
227  ABTI_waitlist_broadcast(p_local, &p_barrier->waitlist);
228  /* Reset counter */
229  p_barrier->counter = 0;
230  ABTD_spinlock_release(&p_barrier->lock);
231  }
232  return ABT_SUCCESS;
233 }
234 
258 int ABT_barrier_get_num_waiters(ABT_barrier barrier, uint32_t *num_waiters)
259 {
260  ABTI_UB_ASSERT(ABTI_initialized());
261  ABTI_UB_ASSERT(num_waiters);
262 
263  ABTI_barrier *p_barrier = ABTI_barrier_get_ptr(barrier);
264  ABTI_CHECK_NULL_BARRIER_PTR(p_barrier);
265 
266  *num_waiters = p_barrier->num_waiters;
267  return ABT_SUCCESS;
268 }
ABT_ERR_BARRIER
#define ABT_ERR_BARRIER
Error code: error related to a barrier.
Definition: abt.h:360
disclaimer
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following disclaimer
Definition: LICENSE_1_0.txt:11
following
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the following
Definition: LICENSE_1_0.txt:10
CONTRACT
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN CONTRACT
Definition: LICENSE_1_0.txt:21
MERCHANTABILITY
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
Definition: LICENSE_1_0.txt:18
grant
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license grant
Definition: LICENSE_1_0.txt:11
license
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this license(the "Software") to use
IMPLIED
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR IMPLIED
Definition: LICENSE_1_0.txt:18
so
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do so
Definition: LICENSE_1_0.txt:8
LIABILITY
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY
Definition: LICENSE_1_0.txt:21
IS
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS IS
Definition: LICENSE_1_0.txt:17
abti.h
FROM
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING FROM
Definition: LICENSE_1_0.txt:22
ABT_barrier
struct ABT_barrier_opaque * ABT_barrier
Barrier handle type.
Definition: abt.h:1029
PURPOSE
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE
Definition: LICENSE_1_0.txt:19
ABTU_malloc
static ABTU_ret_err int ABTU_malloc(size_t size, void **p_ptr)
Definition: abtu.h:235
ABT_barrier_free
int ABT_barrier_free(ABT_barrier *barrier)
Free a barrier.
Definition: barrier.c:144
part
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in part
Definition: LICENSE_1_0.txt:12
charge
Boost Software License Version Permission is hereby free of charge
Definition: LICENSE_1_0.txt:3
distribute
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this distribute
Definition: LICENSE_1_0.txt:5
ABT_SUCCESS
#define ABT_SUCCESS
Error code: the routine returns successfully.
Definition: abt.h:92
ABT_SYNC_EVENT_TYPE_BARRIER
@ ABT_SYNC_EVENT_TYPE_BARRIER
Definition: abt.h:718
ABT_BARRIER_NULL
#define ABT_BARRIER_NULL
Definition: abt.h:1115
ABT_ERR_INV_ARG
#define ABT_ERR_INV_ARG
Error code: invalid user argument.
Definition: abt.h:260
ABTU_free
static void ABTU_free(void *ptr)
Definition: abtu.h:228
OTHERWISE
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR OTHERWISE
Definition: LICENSE_1_0.txt:21
Software
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the Software
Definition: LICENSE_1_0.txt:6
KIND
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY KIND
Definition: LICENSE_1_0.txt:17
granted
Boost Software License Version Permission is hereby granted
Definition: LICENSE_1_0.txt:3
ABT_barrier_reinit
int ABT_barrier_reinit(ABT_barrier barrier, uint32_t num_waiters)
Reinitialize a barrier with a new number of waiters.
Definition: barrier.c:102
execute
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this execute
Definition: LICENSE_1_0.txt:6
August
Boost Software License Version August
Definition: LICENSE_1_0.txt:1
display
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this display
Definition: LICENSE_1_0.txt:5
reproduce
Boost Software License Version Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this reproduce
Definition: LICENSE_1_0.txt:5
ABT_barrier_create
int ABT_barrier_create(uint32_t num_waiters, ABT_barrier *newbarrier)
Create a new barrier.
Definition: barrier.c:47
ABT_barrier_wait
int ABT_barrier_wait(ABT_barrier barrier)
Wait on a barrier.
Definition: barrier.c:197
ABT_barrier_get_num_waiters
int ABT_barrier_get_num_waiters(ABT_barrier barrier, uint32_t *num_waiters)
Get the number of waiters of a barrier.
Definition: barrier.c:258