root/oshmem/shmem/c/shmem_finc.c

/* [<][>][^][v][top][bottom][index][help] */
   1 /*
   2  * Copyright (c) 2013      Mellanox Technologies, Inc.
   3  *                         All rights reserved.
   4  * $COPYRIGHT$
   5  *
   6  * Additional copyrights may follow
   7  *
   8  * $HEADER$
   9  */
  10 #include "oshmem_config.h"
  11 
  12 #include "oshmem/constants.h"
  13 #include "oshmem/include/shmem.h"
  14 #include "oshmem/include/shmemx.h"
  15 
  16 #include "oshmem/runtime/runtime.h"
  17 
  18 #include "oshmem/op/op.h"
  19 #include "oshmem/mca/atomic/atomic.h"
  20 
  21 /*
  22  * These routines perform a fetch-and-increment operation.
  23  * The fetch and increment routines retrieve the value at address target on PE pe, and update
  24  * target with the result of incrementing the retrieved value by one. The operation must be
  25  * completed without the possibility of another process updating target between the time of
  26  * the fetch and the update.
  27  */
  28 #define DO_SHMEM_TYPE_ATOMIC_FETCH_INC(ctx, type_name, type, target, pe, out_value) do { \
  29         int rc = OSHMEM_SUCCESS;                                    \
  30         size_t size;                                                \
  31         type value = 1;                                             \
  32                                                                     \
  33         RUNTIME_CHECK_INIT();                                       \
  34         RUNTIME_CHECK_PE(pe);                                       \
  35         RUNTIME_CHECK_ADDR(target);                                 \
  36                                                                     \
  37         size = sizeof(out_value);                                   \
  38         rc = MCA_ATOMIC_CALL(fadd(                                  \
  39             ctx,                                                    \
  40             (void*)target,                                          \
  41             (void*)&out_value,                                      \
  42             value,                                                  \
  43             size,                                                   \
  44             pe));                                                   \
  45         RUNTIME_CHECK_RC(rc);                                       \
  46     } while (0)
  47 
  48 #define SHMEM_CTX_TYPE_ATOMIC_FETCH_INC(type_name, type, prefix)    \
  49     type prefix##_ctx##type_name##_atomic_fetch_inc(shmem_ctx_t ctx, type *target, int pe) \
  50     {                                                               \
  51         type out_value;                                             \
  52         DO_SHMEM_TYPE_ATOMIC_FETCH_INC(ctx, type_name, type, target,\
  53                                   pe, out_value);                   \
  54         return out_value;                                           \
  55     }
  56 
  57 #define SHMEM_TYPE_ATOMIC_FETCH_INC(type_name, type, prefix)        \
  58     type prefix##type_name##_atomic_fetch_inc(type *target, int pe) \
  59     {                                                               \
  60         type out_value;                                             \
  61         DO_SHMEM_TYPE_ATOMIC_FETCH_INC(oshmem_ctx_default, type_name,\
  62                                   type, target, pe, out_value);     \
  63         return out_value;                                           \
  64     }
  65 
  66 #if OSHMEM_PROFILING
  67 #include "oshmem/include/pshmem.h"
  68 #pragma weak shmem_ctx_int_atomic_fetch_inc = pshmem_ctx_int_atomic_fetch_inc
  69 #pragma weak shmem_ctx_long_atomic_fetch_inc = pshmem_ctx_long_atomic_fetch_inc
  70 #pragma weak shmem_ctx_longlong_atomic_fetch_inc = pshmem_ctx_longlong_atomic_fetch_inc
  71 #pragma weak shmem_ctx_uint_atomic_fetch_inc = pshmem_ctx_uint_atomic_fetch_inc
  72 #pragma weak shmem_ctx_ulong_atomic_fetch_inc = pshmem_ctx_ulong_atomic_fetch_inc
  73 #pragma weak shmem_ctx_ulonglong_atomic_fetch_inc = pshmem_ctx_ulonglong_atomic_fetch_inc
  74 
  75 #pragma weak shmem_int_atomic_fetch_inc = pshmem_int_atomic_fetch_inc
  76 #pragma weak shmem_long_atomic_fetch_inc = pshmem_long_atomic_fetch_inc
  77 #pragma weak shmem_longlong_atomic_fetch_inc = pshmem_longlong_atomic_fetch_inc
  78 #pragma weak shmem_uint_atomic_fetch_inc = pshmem_uint_atomic_fetch_inc
  79 #pragma weak shmem_ulong_atomic_fetch_inc = pshmem_ulong_atomic_fetch_inc
  80 #pragma weak shmem_ulonglong_atomic_fetch_inc = pshmem_ulonglong_atomic_fetch_inc
  81 
  82 #pragma weak shmem_int_finc = pshmem_int_finc
  83 #pragma weak shmem_long_finc = pshmem_long_finc
  84 #pragma weak shmem_longlong_finc = pshmem_longlong_finc
  85 
  86 #pragma weak shmemx_int32_finc = pshmemx_int32_finc
  87 #pragma weak shmemx_int64_finc = pshmemx_int64_finc
  88 #include "oshmem/shmem/c/profile/defines.h"
  89 #endif
  90 
  91 SHMEM_CTX_TYPE_ATOMIC_FETCH_INC(_int, int, shmem)
  92 SHMEM_CTX_TYPE_ATOMIC_FETCH_INC(_long, long, shmem)
  93 SHMEM_CTX_TYPE_ATOMIC_FETCH_INC(_longlong, long long, shmem)
  94 SHMEM_CTX_TYPE_ATOMIC_FETCH_INC(_uint, unsigned int, shmem)
  95 SHMEM_CTX_TYPE_ATOMIC_FETCH_INC(_ulong, unsigned long, shmem)
  96 SHMEM_CTX_TYPE_ATOMIC_FETCH_INC(_ulonglong, unsigned long long, shmem)
  97 SHMEM_TYPE_ATOMIC_FETCH_INC(_int, int, shmem)
  98 SHMEM_TYPE_ATOMIC_FETCH_INC(_long, long, shmem)
  99 SHMEM_TYPE_ATOMIC_FETCH_INC(_longlong, long long, shmem)
 100 SHMEM_TYPE_ATOMIC_FETCH_INC(_uint, unsigned int, shmem)
 101 SHMEM_TYPE_ATOMIC_FETCH_INC(_ulong, unsigned long, shmem)
 102 SHMEM_TYPE_ATOMIC_FETCH_INC(_ulonglong, unsigned long long, shmem)
 103 
 104 /* deprecated APIs */
 105 #define SHMEM_TYPE_FINC(type_name, type, prefix)                    \
 106     type prefix##type_name##_finc(type *target, int pe)             \
 107     {                                                               \
 108         type out_value;                                             \
 109         DO_SHMEM_TYPE_ATOMIC_FETCH_INC(oshmem_ctx_default, type_name,   \
 110                                   type, target, pe, out_value);     \
 111         return out_value;                                           \
 112     }
 113 
 114 SHMEM_TYPE_FINC(_int, int, shmem)
 115 SHMEM_TYPE_FINC(_long, long, shmem)
 116 SHMEM_TYPE_FINC(_longlong, long long, shmem)
 117 SHMEM_TYPE_FINC(_int32, int32_t, shmemx)
 118 SHMEM_TYPE_FINC(_int64, int64_t, shmemx)

/* [<][>][^][v][top][bottom][index][help] */