root/oshmem/shmem/c/shmem_add.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 #include "oshmem/op/op.h"
  18 #include "oshmem/mca/atomic/atomic.h"
  19 
  20 /*
  21  * These routines perform an atomic add operation.
  22  * The atomic add routines add value to the data at address target on PE pe. The operation
  23  * must be completed without the possibility of another process updating target between the
  24  * time of the fetch and the update.
  25  */
  26 #define DO_SHMEM_TYPE_ATOMIC_ADD(ctx, type_name, type, target, value, pe) { \
  27         int rc = OSHMEM_SUCCESS;                                    \
  28         size_t size = 0;                                            \
  29                                                                     \
  30         RUNTIME_CHECK_INIT();                                       \
  31         RUNTIME_CHECK_PE(pe);                                       \
  32         RUNTIME_CHECK_ADDR(target);                                 \
  33                                                                     \
  34         size = sizeof(value);                                       \
  35         rc = MCA_ATOMIC_CALL(add(                                   \
  36             ctx,                                                    \
  37             (void*)target,                                          \
  38             value,                                                  \
  39             size,                                                   \
  40             pe));                                                   \
  41         RUNTIME_CHECK_RC(rc);                                       \
  42     } while (0)
  43 
  44 #define SHMEM_CTX_TYPE_ATOMIC_ADD(type_name, type, prefix)          \
  45     void prefix##_ctx##type_name##_atomic_add(shmem_ctx_t ctx, type *target, type value, int pe) \
  46     {                                                               \
  47         DO_SHMEM_TYPE_ATOMIC_ADD(ctx, type_name, type, target,      \
  48                                  value, pe);                        \
  49         return ;                                                    \
  50     }
  51 
  52 #define SHMEM_TYPE_ATOMIC_ADD(type_name, type, prefix)              \
  53     void prefix##type_name##_atomic_add(type *target, type value, int pe) \
  54     {                                                               \
  55         DO_SHMEM_TYPE_ATOMIC_ADD(oshmem_ctx_default, type_name,     \
  56                                  type, target, value, pe);          \
  57                                                                     \
  58         return ;                                                    \
  59     }
  60 
  61 #if OSHMEM_PROFILING
  62 #include "oshmem/include/pshmem.h"
  63 #pragma weak shmem_ctx_int_atomic_add = pshmem_ctx_int_atomic_add
  64 #pragma weak shmem_ctx_long_atomic_add = pshmem_ctx_long_atomic_add
  65 #pragma weak shmem_ctx_longlong_atomic_add = pshmem_ctx_longlong_atomic_add
  66 #pragma weak shmem_ctx_uint_atomic_add = pshmem_ctx_uint_atomic_add
  67 #pragma weak shmem_ctx_ulong_atomic_add = pshmem_ctx_ulong_atomic_add
  68 #pragma weak shmem_ctx_ulonglong_atomic_add = pshmem_ctx_ulonglong_atomic_add
  69 
  70 #pragma weak shmem_int_atomic_add = pshmem_int_atomic_add
  71 #pragma weak shmem_long_atomic_add = pshmem_long_atomic_add
  72 #pragma weak shmem_longlong_atomic_add = pshmem_longlong_atomic_add
  73 #pragma weak shmem_uint_atomic_add = pshmem_uint_atomic_add
  74 #pragma weak shmem_ulong_atomic_add = pshmem_ulong_atomic_add
  75 #pragma weak shmem_ulonglong_atomic_add = pshmem_ulonglong_atomic_add
  76 
  77 #pragma weak shmem_int_add = pshmem_int_add
  78 #pragma weak shmem_long_add = pshmem_long_add
  79 #pragma weak shmem_longlong_add = pshmem_longlong_add
  80 
  81 #pragma weak shmemx_int32_add = pshmemx_int32_add
  82 #pragma weak shmemx_int64_add = pshmemx_int64_add
  83 #include "oshmem/shmem/c/profile/defines.h"
  84 #endif
  85 
  86 SHMEM_CTX_TYPE_ATOMIC_ADD(_uint, unsigned int, shmem)
  87 SHMEM_CTX_TYPE_ATOMIC_ADD(_ulong, unsigned long, shmem)
  88 SHMEM_CTX_TYPE_ATOMIC_ADD(_ulonglong, unsigned long long, shmem)
  89 SHMEM_CTX_TYPE_ATOMIC_ADD(_int, int, shmem)
  90 SHMEM_CTX_TYPE_ATOMIC_ADD(_long, long, shmem)
  91 SHMEM_CTX_TYPE_ATOMIC_ADD(_longlong, long long, shmem)
  92 SHMEM_TYPE_ATOMIC_ADD(_int, int, shmem)
  93 SHMEM_TYPE_ATOMIC_ADD(_long, long, shmem)
  94 SHMEM_TYPE_ATOMIC_ADD(_longlong, long long, shmem)
  95 SHMEM_TYPE_ATOMIC_ADD(_uint, unsigned int, shmem)
  96 SHMEM_TYPE_ATOMIC_ADD(_ulong, unsigned long, shmem)
  97 SHMEM_TYPE_ATOMIC_ADD(_ulonglong, unsigned long long, shmem)
  98 
  99 /* deprecated APIs */
 100 #define SHMEM_TYPE_ADD(type_name, type, prefix)                     \
 101     void prefix##type_name##_add(type *target, type value, int pe)  \
 102     {                                                               \
 103         DO_SHMEM_TYPE_ATOMIC_ADD(oshmem_ctx_default, type_name,      \
 104                                  type, target, value, pe);          \
 105         return ;                                                    \
 106     }
 107 
 108 SHMEM_TYPE_ADD(_int, int, shmem)
 109 SHMEM_TYPE_ADD(_long, long, shmem)
 110 SHMEM_TYPE_ADD(_longlong, long long, shmem)
 111 SHMEM_TYPE_ADD(_int32, int32_t, shmemx)
 112 SHMEM_TYPE_ADD(_int64, int64_t, shmemx)

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