root/oshmem/shmem/c/shmem_fadd.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 an atomic fetch-and-add operation.
  23  * The fetch and add routines retrieve the value at address target on PE pe, and update
  24  * target with the result of adding value to the retrieved value. The operation must be completed
  25  * without the possibility of another process updating target between the time of the
  26  * fetch and the update.
  27  */
  28 #define DO_SHMEM_TYPE_ATOMIC_FETCH_ADD(ctx, type_name, type, target, value, pe, out_value) do { \
  29         int rc = OSHMEM_SUCCESS;                                    \
  30         size_t size = 0;                                            \
  31                                                                     \
  32         RUNTIME_CHECK_INIT();                                       \
  33         RUNTIME_CHECK_PE(pe);                                       \
  34         RUNTIME_CHECK_ADDR(target);                                 \
  35                                                                     \
  36         size = sizeof(out_value);                                   \
  37         rc = MCA_ATOMIC_CALL(fadd(                                  \
  38             ctx,                                                    \
  39             (void*)target,                                          \
  40             (void*)&out_value,                                      \
  41             value,                                                  \
  42             size,                                                   \
  43             pe));                                                   \
  44         RUNTIME_CHECK_RC(rc);                                       \
  45     } while (0)
  46 
  47 #define SHMEM_CTX_TYPE_ATOMIC_FETCH_ADD(type_name, type, prefix)         \
  48     type prefix##_ctx##type_name##_atomic_fetch_add(shmem_ctx_t ctx, type *target, type value, int pe) \
  49     {                                                               \
  50         type out_value;                                             \
  51         DO_SHMEM_TYPE_ATOMIC_FETCH_ADD(ctx, type_name, type, target,     \
  52                                   value, pe, out_value);            \
  53         return out_value;                                           \
  54     }
  55 
  56 #define SHMEM_TYPE_ATOMIC_FETCH_ADD(type_name, type, prefix)             \
  57     type prefix##type_name##_atomic_fetch_add(type *target, type value, int pe)\
  58     {                                                               \
  59         type out_value;                                             \
  60         DO_SHMEM_TYPE_ATOMIC_FETCH_ADD(oshmem_ctx_default, type_name,    \
  61                                   type, target, value, pe, out_value); \
  62         return out_value;                                           \
  63     }
  64 
  65 #if OSHMEM_PROFILING
  66 #include "oshmem/include/pshmem.h"
  67 #pragma weak shmem_ctx_int_atomic_fetch_add = pshmem_ctx_int_atomic_fetch_add
  68 #pragma weak shmem_ctx_long_atomic_fetch_add = pshmem_ctx_long_atomic_fetch_add
  69 #pragma weak shmem_ctx_longlong_atomic_fetch_add = pshmem_ctx_longlong_atomic_fetch_add
  70 #pragma weak shmem_ctx_uint_atomic_fetch_add = pshmem_ctx_uint_atomic_fetch_add
  71 #pragma weak shmem_ctx_ulong_atomic_fetch_add = pshmem_ctx_ulong_atomic_fetch_add
  72 #pragma weak shmem_ctx_ulonglong_atomic_fetch_add = pshmem_ctx_ulonglong_atomic_fetch_add
  73 
  74 #pragma weak shmem_int_atomic_fetch_add = pshmem_int_atomic_fetch_add
  75 #pragma weak shmem_long_atomic_fetch_add = pshmem_long_atomic_fetch_add
  76 #pragma weak shmem_longlong_atomic_fetch_add = pshmem_longlong_atomic_fetch_add
  77 #pragma weak shmem_uint_atomic_fetch_add = pshmem_uint_atomic_fetch_add
  78 #pragma weak shmem_ulong_atomic_fetch_add = pshmem_ulong_atomic_fetch_add
  79 #pragma weak shmem_ulonglong_atomic_fetch_add = pshmem_ulonglong_atomic_fetch_add
  80 
  81 #pragma weak shmem_int_fadd = pshmem_int_fadd
  82 #pragma weak shmem_long_fadd = pshmem_long_fadd
  83 #pragma weak shmem_longlong_fadd = pshmem_longlong_fadd
  84 
  85 #pragma weak shmemx_int32_fadd = pshmemx_int32_fadd
  86 #pragma weak shmemx_int64_fadd = pshmemx_int64_fadd
  87 #include "oshmem/shmem/c/profile/defines.h"
  88 #endif
  89 
  90 SHMEM_CTX_TYPE_ATOMIC_FETCH_ADD(_int, int, shmem)
  91 SHMEM_CTX_TYPE_ATOMIC_FETCH_ADD(_long, long, shmem)
  92 SHMEM_CTX_TYPE_ATOMIC_FETCH_ADD(_longlong, long long, shmem)
  93 SHMEM_CTX_TYPE_ATOMIC_FETCH_ADD(_uint, unsigned int, shmem)
  94 SHMEM_CTX_TYPE_ATOMIC_FETCH_ADD(_ulong, unsigned long, shmem)
  95 SHMEM_CTX_TYPE_ATOMIC_FETCH_ADD(_ulonglong, unsigned long long, shmem)
  96 SHMEM_TYPE_ATOMIC_FETCH_ADD(_int, int, shmem)
  97 SHMEM_TYPE_ATOMIC_FETCH_ADD(_long, long, shmem)
  98 SHMEM_TYPE_ATOMIC_FETCH_ADD(_longlong, long long, shmem)
  99 SHMEM_TYPE_ATOMIC_FETCH_ADD(_uint, unsigned int, shmem)
 100 SHMEM_TYPE_ATOMIC_FETCH_ADD(_ulong, unsigned long, shmem)
 101 SHMEM_TYPE_ATOMIC_FETCH_ADD(_ulonglong, unsigned long long, shmem)
 102 
 103 /* deprecated APIs */
 104 #define SHMEM_TYPE_FADD(type_name, type, prefix)                    \
 105     type prefix##type_name##_fadd(type *target, type value, int pe) \
 106     {                                                               \
 107         type out_value;                                             \
 108         DO_SHMEM_TYPE_ATOMIC_FETCH_ADD(oshmem_ctx_default, type_name, \
 109                                        type, target, value, pe, out_value); \
 110         return out_value;                                           \
 111     }
 112 
 113 SHMEM_TYPE_FADD(_int, int, shmem)
 114 SHMEM_TYPE_FADD(_long, long, shmem)
 115 SHMEM_TYPE_FADD(_longlong, long long, shmem)
 116 SHMEM_TYPE_FADD(_int32, int32_t, shmemx)
 117 SHMEM_TYPE_FADD(_int64, int64_t, shmemx)

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