⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 op_predefined.c

📁 MPI stands for the Message Passing Interface. Written by the MPI Forum (a large committee comprising
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana *                         University Research and Technology *                         Corporation.  All rights reserved. * Copyright (c) 2004-2006 The University of Tennessee and The University *                         of Tennessee Research Foundation.  All rights *                         reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,  *                         University of Stuttgart.  All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. *                         All rights reserved. * Copyright (c) 2006      Cisco Systems, Inc.  All rights reserved. * $COPYRIGHT$ *  * Additional copyrights may follow *  * $HEADER$ */#include "ompi_config.h"#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#include "ompi/op/op.h"#include "ompi/op/op_predefined.h"/* * Since all the functions in this file are essentially identical, we * use a macro to substitute in names and types.  The core operation * in all functions that use this macro is the same. * * This macro is for (out op in). */#define OP_FUNC(name, type_name, type, op) \  void ompi_mpi_op_##name##_##type_name(void *in, void *out, int *count, \                                        MPI_Datatype *dtype)             \  {                                                                      \    int i;                                                               \    type *a = (type *) in;                                               \    type *b = (type *) out;                                              \    for (i = 0; i < *count; ++i) {                                       \      *(b++) op *(a++);                                                  \    }                                                                    \  }#define COMPLEX_OP_FUNC_SUM(type_name, type) \  void ompi_mpi_op_sum_##type_name(void *in, void *out, int *count,      \                                   MPI_Datatype *dtype)                  \  {                                                                      \    int i;                                                               \    type *a = (type *) in;                                               \    type *b = (type *) out;                                              \    for (i = 0; i < *count; ++i, ++b, ++a) {                             \      b->real += a->real;                                                \      b->imag += a->imag;                                                \    }                                                                    \  }#define COMPLEX_OP_FUNC_PROD(type_name, type) \  void ompi_mpi_op_prod_##type_name(void *in, void *out, int *count,     \                                   MPI_Datatype *dtype)                  \  {                                                                      \    int i;                                                               \    type *a = (type *) in;                                               \    type *b = (type *) out;                                              \    type temp;                                                           \    for (i = 0; i < *count; ++i, ++b, ++a) {                             \      temp.real = a->real * b->real - a->imag * b->imag;                 \      temp.imag = a->imag * b->real + a->real * b->imag;                 \      *b = temp;                                                         \    }                                                                    \  }/* * Since all the functions in this file are essentially identical, we * use a macro to substitute in names and types.  The core operation * in all functions that use this macro is the same. * * This macro is for (out = op(out, in)) */#define FUNC_FUNC(name, type_name, type) \  void ompi_mpi_op_##name##_##type_name(void *in, void *out, int *count, \                                        MPI_Datatype *dtype)             \  {                                                                      \    int i;                                                               \    type *a = (type *) in;                                               \    type *b = (type *) out;                                              \    for (i = 0; i < *count; ++i) {                                       \      *(b) = current_func(*(b), *(a));                                   \      ++b;                                                               \      ++a;                                                               \    }                                                                    \  }/* * Since all the functions in this file are essentially identical, we * use a macro to substitute in names and types.  The core operation * in all functions that use this macro is the same. * * This macro is for minloc and maxloc */#define LOC_STRUCT(type_name, type1, type2) \  typedef struct { \    type1 v; \    type2 k; \  } ompi_op_predefined_##type_name##_t;#define LOC_FUNC(name, type_name, op) \  void ompi_mpi_op_##name##_##type_name(void *in, void *out, int *count, \                                        MPI_Datatype *dtype) \  { \    int i; \    ompi_op_predefined_##type_name##_t *a = (ompi_op_predefined_##type_name##_t*) in; \    ompi_op_predefined_##type_name##_t *b = (ompi_op_predefined_##type_name##_t*) out; \    for (i = 0; i < *count; ++i, ++a, ++b) { \      if (a->v op b->v) { \        b->v = a->v; \        b->k = a->k; \      } else if (a->v == b->v) { \        b->k = (b->k < a->k ? b->k : a->k); \      } \    } \  }/************************************************************************* * Max *************************************************************************/#undef current_func#define current_func(a, b) ((a) > (b) ? (a) : (b))/* C integer */FUNC_FUNC(max, signed_char, signed char)FUNC_FUNC(max, unsigned_char, unsigned char)FUNC_FUNC(max, int, int)FUNC_FUNC(max, long, long)FUNC_FUNC(max, short, short)FUNC_FUNC(max, unsigned_short, unsigned short)FUNC_FUNC(max, unsigned, unsigned)FUNC_FUNC(max, unsigned_long, unsigned long)#if HAVE_LONG_LONGFUNC_FUNC(max, long_long_int, long long int)FUNC_FUNC(max, unsigned_long_long, unsigned long long)#endif/* Fortran integer */#if OMPI_HAVE_FORTRAN_INTEGERFUNC_FUNC(max, fortran_integer, ompi_fortran_integer_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER1FUNC_FUNC(max, fortran_integer1, ompi_fortran_integer1_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER2FUNC_FUNC(max, fortran_integer2, ompi_fortran_integer2_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER4FUNC_FUNC(max, fortran_integer4, ompi_fortran_integer4_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER8FUNC_FUNC(max, fortran_integer8, ompi_fortran_integer8_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER16FUNC_FUNC(max, fortran_integer16, ompi_fortran_integer16_t)#endif/* Floating point */FUNC_FUNC(max, float, float)FUNC_FUNC(max, double, double)#if OMPI_HAVE_FORTRAN_REALFUNC_FUNC(max, fortran_real, ompi_fortran_real_t)#endif#if OMPI_HAVE_FORTRAN_DOUBLE_PRECISIONFUNC_FUNC(max, fortran_double_precision, ompi_fortran_double_precision_t)#endifFUNC_FUNC(max, long_double, long double)#if OMPI_HAVE_FORTRAN_REAL4FUNC_FUNC(max, fortran_real4, ompi_fortran_real4_t)#endif#if OMPI_HAVE_FORTRAN_REAL8FUNC_FUNC(max, fortran_real8, ompi_fortran_real8_t)#endif#if OMPI_HAVE_FORTRAN_REAL16FUNC_FUNC(max, fortran_real16, ompi_fortran_real16_t)#endif/************************************************************************* * Min *************************************************************************/#undef current_func#define current_func(a, b) ((a) < (b) ? (a) : (b))/* C integer */FUNC_FUNC(min, signed_char, signed char)FUNC_FUNC(min, unsigned_char, unsigned char)FUNC_FUNC(min, int, int)FUNC_FUNC(min, long, long)FUNC_FUNC(min, short, short)FUNC_FUNC(min, unsigned_short, unsigned short)FUNC_FUNC(min, unsigned, unsigned)FUNC_FUNC(min, unsigned_long, unsigned long)#if HAVE_LONG_LONGFUNC_FUNC(min, long_long_int, long long int)FUNC_FUNC(min, unsigned_long_long, unsigned long long)#endif/* Fortran integer */#if OMPI_HAVE_FORTRAN_INTEGERFUNC_FUNC(min, fortran_integer, ompi_fortran_integer_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER1FUNC_FUNC(min, fortran_integer1, ompi_fortran_integer1_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER2FUNC_FUNC(min, fortran_integer2, ompi_fortran_integer2_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER4FUNC_FUNC(min, fortran_integer4, ompi_fortran_integer4_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER8FUNC_FUNC(min, fortran_integer8, ompi_fortran_integer8_t)#endif#if OMPI_HAVE_FORTRAN_INTEGER16FUNC_FUNC(min, fortran_integer16, ompi_fortran_integer16_t)#endif/* Floating point */FUNC_FUNC(min, float, float)FUNC_FUNC(min, double, double)#if OMPI_HAVE_FORTRAN_REALFUNC_FUNC(min, fortran_real, ompi_fortran_real_t)#endif#if OMPI_HAVE_FORTRAN_DOUBLE_PRECISIONFUNC_FUNC(min, fortran_double_precision, ompi_fortran_double_precision_t)#endifFUNC_FUNC(min, long_double, long double)#if OMPI_HAVE_FORTRAN_REAL4FUNC_FUNC(min, fortran_real4, ompi_fortran_real4_t)#endif#if OMPI_HAVE_FORTRAN_REAL8FUNC_FUNC(min, fortran_real8, ompi_fortran_real8_t)#endif#if OMPI_HAVE_FORTRAN_REAL16FUNC_FUNC(min, fortran_real16, ompi_fortran_real16_t)#endif/************************************************************************* * Sum *************************************************************************//* C integer */OP_FUNC(sum, signed_char, signed char, +=)OP_FUNC(sum, unsigned_char, unsigned char, +=)OP_FUNC(sum, int, int, +=)OP_FUNC(sum, long, long, +=)OP_FUNC(sum, short, short, +=)OP_FUNC(sum, unsigned_short, unsigned short, +=)OP_FUNC(sum, unsigned, unsigned, +=)OP_FUNC(sum, unsigned_long, unsigned long, +=)#if HAVE_LONG_LONGOP_FUNC(sum, long_long_int, long long int, +=)OP_FUNC(sum, unsigned_long_long, unsigned long long, +=)#endif/* Fortran integer */#if OMPI_HAVE_FORTRAN_INTEGEROP_FUNC(sum, fortran_integer, ompi_fortran_integer_t, +=)#endif#if OMPI_HAVE_FORTRAN_INTEGER1OP_FUNC(sum, fortran_integer1, ompi_fortran_integer1_t, +=)#endif#if OMPI_HAVE_FORTRAN_INTEGER2OP_FUNC(sum, fortran_integer2, ompi_fortran_integer2_t, +=)#endif#if OMPI_HAVE_FORTRAN_INTEGER4OP_FUNC(sum, fortran_integer4, ompi_fortran_integer4_t, +=)#endif#if OMPI_HAVE_FORTRAN_INTEGER8OP_FUNC(sum, fortran_integer8, ompi_fortran_integer8_t, +=)#endif#if OMPI_HAVE_FORTRAN_INTEGER16OP_FUNC(sum, fortran_integer16, ompi_fortran_integer16_t, +=)#endif/* Floating point */OP_FUNC(sum, float, float, +=)OP_FUNC(sum, double, double, +=)#if OMPI_HAVE_FORTRAN_REALOP_FUNC(sum, fortran_real, ompi_fortran_real_t, +=)#endif#if OMPI_HAVE_FORTRAN_DOUBLE_PRECISIONOP_FUNC(sum, fortran_double_precision, ompi_fortran_double_precision_t, +=)#endifOP_FUNC(sum, long_double, long double, +=)#if OMPI_HAVE_FORTRAN_REAL4OP_FUNC(sum, fortran_real4, ompi_fortran_real4_t, +=)#endif#if OMPI_HAVE_FORTRAN_REAL8OP_FUNC(sum, fortran_real8, ompi_fortran_real8_t, +=)#endif#if OMPI_HAVE_FORTRAN_REAL16OP_FUNC(sum, fortran_real16, ompi_fortran_real16_t, +=)#endif/* Complex */#if OMPI_HAVE_FORTRAN_REAL && OMPI_HAVE_FORTRAN_COMPLEXCOMPLEX_OP_FUNC_SUM(fortran_complex, ompi_fortran_complex_t)#endif#if OMPI_HAVE_FORTRAN_DOUBLE_PRECISION && OMPI_HAVE_FORTRAN_COMPLEXCOMPLEX_OP_FUNC_SUM(fortran_double_complex, ompi_fortran_double_complex_t)#endif#if OMPI_HAVE_FORTRAN_REAL4 && OMPI_HAVE_FORTRAN_COMPLEX8COMPLEX_OP_FUNC_SUM(fortran_complex8, ompi_fortran_complex8_t)#endif#if OMPI_HAVE_FORTRAN_REAL8 && OMPI_HAVE_FORTRAN_COMPLEX16COMPLEX_OP_FUNC_SUM(fortran_complex16, ompi_fortran_complex16_t)#endif#if OMPI_HAVE_FORTRAN_REAL16 && OMPI_HAVE_FORTRAN_COMPLEX32COMPLEX_OP_FUNC_SUM(fortran_complex32, ompi_fortran_complex32_t)#endif/************************************************************************* * Product *************************************************************************//* C integer */OP_FUNC(prod, signed_char, signed char, *=)OP_FUNC(prod, unsigned_char, unsigned char, *=)OP_FUNC(prod, int, int, *=)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -