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

📄 same_dtype.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
📖 第 1 页 / 共 3 页
字号:
/*   (C) 2004 by Argonne National Laboratory.       See COPYRIGHT in top-level directory.*/#include "collchk.h" /* AIX requires this to be the first thing in the file.  */#ifndef __GNUC__# if HAVE_ALLOCA_H#  include <alloca.h># else#  ifdef _AIX #pragma alloca#  else#   ifndef alloca /* predefined by HP cc +Olibcalls */char *alloca ();#   endif#  endif# endif#else# if defined( HAVE_ALLOCA_H )# include <alloca.h># endif#endifunsigned int CollChk_cirleftshift( unsigned int alpha, unsigned n );unsigned int CollChk_cirleftshift( unsigned int alpha, unsigned n ){    /* Doing circular left shift of alpha by n bits */    unsigned int t1, t2;    t1 = alpha >> (sizeof(unsigned int)-n);    t2 = alpha << n;    return t1 | t2;}void CollChk_hash_add(const CollChk_hash_t *alpha,                      const CollChk_hash_t *beta,                            CollChk_hash_t *lamda);void CollChk_hash_add(const CollChk_hash_t *alpha,                      const CollChk_hash_t *beta,                            CollChk_hash_t *lamda){    lamda->value = (alpha->value)                 ^ CollChk_cirleftshift(beta->value, alpha->count);    lamda->count = alpha->count + beta->count;}int CollChk_hash_equal(const CollChk_hash_t *alpha,                       const CollChk_hash_t *beta){    return alpha->count == beta->count && alpha->value == beta->value;}#if defined( HAVE_LAM_FORTRAN_MPI_DATATYPE_IN_C )#include "lam_f2c_dtype.h"#endifunsigned int CollChk_basic_value(MPI_Datatype type);unsigned int CollChk_basic_value(MPI_Datatype type){    /*       MPI_Datatype's that return 0x0 are as if they are being       skipped/ignored in the comparison of any 2 MPI_Datatypes.    */    if ( type == MPI_DATATYPE_NULL || type == MPI_UB || type == MPI_LB )        return 0x0;    else if ( type == MPI_CHAR )        return 0x1;#if defined( HAVE_MPI_SIGNED_CHAR )    else if ( type == MPI_SIGNED_CHAR )        return 0x3;#endif    else if ( type == MPI_UNSIGNED_CHAR )        return 0x5;    else if ( type == MPI_BYTE )        return 0x7;#if defined( HAVE_MPI_WCHAR )    else if ( type == MPI_WCHAR )        return 0x9;#endif    else if ( type == MPI_SHORT )        return 0xb;    else if ( type == MPI_UNSIGNED_SHORT )        return 0xd;    else if ( type == MPI_INT )        return 0xf;    else if ( type == MPI_UNSIGNED )        return 0x11;    else if ( type == MPI_LONG )        return 0x13;    else if ( type == MPI_UNSIGNED_LONG )        return 0x15;    else if ( type == MPI_FLOAT )        return 0x17;    else if ( type == MPI_DOUBLE )        return 0x19;    else if ( type == MPI_LONG_DOUBLE )        return 0x1b;    else if ( type == MPI_LONG_LONG_INT )        return 0x1d;    /* else if ( type == MPI_LONG_LONG ) return 0x1f; */#if defined( HAVE_MPI_UNSIGNED_LONG_LONG )    else if ( type == MPI_UNSIGNED_LONG_LONG )        return 0x21;#endif    else if ( type == MPI_FLOAT_INT )        return 0x8;       /* (0x17,1)@(0xf,1) */    else if ( type == MPI_DOUBLE_INT )        return 0x6;       /* (0x19,1)@(0xf,1) */    else if ( type == MPI_LONG_INT )        return 0xc;       /* (0x13,1)@(0xf,1) */    else if ( type == MPI_SHORT_INT )        return 0x14;      /* (0xb,1)@(0xf,1) */    else if ( type == MPI_2INT )        return 0x10;      /* (0xf,1)@(0xf,1) */    else if ( type == MPI_LONG_DOUBLE_INT )        return 0x4;       /* (0x1b,1)@(0xf,1) */#if defined( HAVE_FORTRAN_MPI_DATATYPE_IN_C )    else if ( type == MPI_COMPLEX )        return 0x101;    else if ( type == MPI_DOUBLE_COMPLEX )        return 0x103;    else if ( type == MPI_LOGICAL )        return 0x105;    else if ( type == MPI_REAL )        return 0x107;    else if ( type == MPI_DOUBLE_PRECISION )        return 0x109;    else if ( type == MPI_INTEGER )        return 0x10b;    else if ( type == MPI_CHARACTER )        return 0x10d;    else if ( type == MPI_2INTEGER )        return 0x33c;      /* (0x10b,1)@(0x10b,1) */    else if ( type == MPI_2REAL )        return 0x329;      /* (0x107,1)@(0x107,1) */    else if ( type == MPI_2DOUBLE_PRECISION )        return 0x33a;      /* (0x109,1)@(0x109,1) */#if defined( HAVE_FORTRAN_MPI_DATATYPE_COMPLEXX_IN_C )    else if ( type == MPI_2COMPLEX )        return 0x323;      /* (0x101,1)@(0x101,1) */    else if ( type == MPI_2DOUBLE_COMPLEX )        return 0x325;      /* (0x103,1)@(0x103,1) */#endif    else if ( type == MPI_PACKED )        return 0x201;#if defined( HAVE_FORTRAN_MPI_DATATYPE_INTEGERX_IN_C )    else if ( type == MPI_INTEGER1 )        return 0x211;    else if ( type == MPI_INTEGER2 )        return 0x213;    else if ( type == MPI_INTEGER4 )        return 0x215;    else if ( type == MPI_INTEGER8 )        return 0x217;    /* else if ( type == MPI_INTEGER16 ) return 0x219; */#endif#if defined( HAVE_FORTRAN_MPI_DATATYPE_REALX_IN_C )    else if ( type == MPI_REAL4 )        return 0x221;    else if ( type == MPI_REAL8 )        return 0x223;    /* else if ( type == MPI_REAL16 ) return 0x205; */#endif#if defined( HAVE_FORTRAN_MPI_DATATYPE_COMPLEXX_IN_C )    else if ( type == MPI_COMPLEX8 )        return 0x231;    else if ( type == MPI_COMPLEX16 )        return 0x233;    /* else if ( type == MPI_COMPLEX32 ) return 0x20b; */#endif#endif    else {#if defined( HAVE_INT_MPI_DATATYPE )        fprintf( stderr, "CollChk_basic_value()) "                         "Unknown basic MPI datatype %x.\n", type );#elif defined( HAVE_PTR_MPI_DATATYPE )        fprintf( stderr, "CollChk_basic_value()) "                         "Unknown basic MPI datatype %p.\n", type );#else        fprintf( stderr, "CollChk_basic_value()) "                         "Unknown basic MPI datatype.\n" );#endif        fflush( stderr );        return 0;    }}unsigned int CollChk_basic_count(MPI_Datatype type);unsigned int CollChk_basic_count(MPI_Datatype type){    /* MPI_Datatype's that return 0 are being skipped/ignored. */    if (    type == MPI_DATATYPE_NULL         || type == MPI_UB         || type == MPI_LB    ) return 0;    else if (    type == MPI_CHAR#if defined( HAVE_MPI_SIGNED_CHAR )              || type == MPI_SIGNED_CHAR#endif              || type == MPI_UNSIGNED_CHAR              || type == MPI_BYTE#if defined( HAVE_MPI_WCHAR )              || type == MPI_WCHAR#endif              || type == MPI_SHORT              || type == MPI_UNSIGNED_SHORT              || type == MPI_INT              || type == MPI_UNSIGNED              || type == MPI_LONG              || type == MPI_UNSIGNED_LONG              || type == MPI_FLOAT              || type == MPI_DOUBLE              || type == MPI_LONG_DOUBLE              || type == MPI_LONG_LONG_INT              /* || type == MPI_LONG_LONG */#if defined( HAVE_MPI_UNSIGNED_LONG_LONG )              || type == MPI_UNSIGNED_LONG_LONG#endif    ) return 1;    else if (    type == MPI_FLOAT_INT              || type == MPI_DOUBLE_INT              || type == MPI_LONG_INT              || type == MPI_SHORT_INT              || type == MPI_2INT              || type == MPI_LONG_DOUBLE_INT    ) return 2;#if defined( HAVE_FORTRAN_MPI_DATATYPE_IN_C )    else if (    type == MPI_COMPLEX              || type == MPI_DOUBLE_COMPLEX              || type == MPI_LOGICAL              || type == MPI_REAL              || type == MPI_DOUBLE_PRECISION              || type == MPI_INTEGER              || type == MPI_CHARACTER    ) return 1;    else if (    type == MPI_2INTEGER              || type == MPI_2REAL              || type == MPI_2DOUBLE_PRECISION#if defined( HAVE_FORTRAN_MPI_DATATYPE_COMPLEXX_IN_C )              || type == MPI_2COMPLEX              || type == MPI_2DOUBLE_COMPLEX#endif    ) return 2;    else if (    type == MPI_PACKED#if defined( HAVE_FORTRAN_MPI_DATATYPE_INTEGERX_IN_C )              || type == MPI_INTEGER1              || type == MPI_INTEGER2              || type == MPI_INTEGER4              || type == MPI_INTEGER8        /* || type == MPI_INTEGER16 */#endif#if defined( HAVE_FORTRAN_MPI_DATATYPE_REALX_IN_C )              || type == MPI_REAL4              || type == MPI_REAL8        /* || type == MPI_REAL16 */#endif#if defined( HAVE_FORTRAN_MPI_DATATYPE_COMPLEXX_IN_C )              || type == MPI_COMPLEX8              || type == MPI_COMPLEX16        /* || type == MPI_COMPLEX32 */#endif    ) return 1;#endif    else {#if defined( HAVE_INT_MPI_DATATYPE )        fprintf( stderr, "CollChk_basic_count(): "                         "Unknown basic MPI datatype %x.\n", type );#elif defined( HAVE_PTR_MPI_DATATYPE )        fprintf( stderr, "CollChk_basic_count(): "                         "Unknown basic MPI datatype %p.\n", type );#else        fprintf( stderr, "CollChk_basic_count(): "                         "Unknown basic MPI datatype.\n" );#endif        fflush( stderr );        return 0;    }}int CollChk_derived_count(int idx, int *ints, int combiner);int CollChk_derived_count(int idx, int *ints, int combiner){    int ii, tot_cnt;#if defined( HAVE_RARE_MPI_COMBINERS )    int dim_A, dim_B;#endif        tot_cnt = 0;    switch(combiner) {#if defined( HAVE_RARE_MPI_COMBINERS )        case MPI_COMBINER_DUP :         case MPI_COMBINER_F90_REAL :        case MPI_COMBINER_F90_COMPLEX :        case MPI_COMBINER_F90_INTEGER :        case MPI_COMBINER_RESIZED :            return 1;#endif        case MPI_COMBINER_CONTIGUOUS :            return ints[0];#if defined( HAVE_RARE_MPI_COMBINERS )        case MPI_COMBINER_HVECTOR_INTEGER :        case MPI_COMBINER_INDEXED_BLOCK :#endif        case MPI_COMBINER_VECTOR :        case MPI_COMBINER_HVECTOR :            return ints[0]*ints[1];#if defined( HAVE_RARE_MPI_COMBINERS )        case MPI_COMBINER_HINDEXED_INTEGER :#endif        case MPI_COMBINER_INDEXED :        case MPI_COMBINER_HINDEXED :            for ( ii = ints[0]; ii > 0; ii-- ) {                 tot_cnt += ints[ ii ];            }            return tot_cnt;#if defined( HAVE_RARE_MPI_COMBINERS )        case MPI_COMBINER_STRUCT_INTEGER :#endif        case MPI_COMBINER_STRUCT :            return ints[idx+1];#if defined( HAVE_RARE_MPI_COMBINERS )        case MPI_COMBINER_SUBARRAY :

⌨️ 快捷键说明

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