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

📄 copy_functions_heterogeneous.c

📁 MPI stands for the Message Passing Interface. Written by the MPI Forum (a large committee comprising
💻 C
📖 第 1 页 / 共 2 页
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* * Copyright (c) 2004-2006 The University of Tennessee and The University *                         of Tennessee Research Foundation.  All rights *                         reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */#include "ompi_config.h"#include "opal/util/output.h"#include "opal/types.h"#include "ompi/datatype/dt_arch.h"#include "ompi/datatype/datatype.h"#include "ompi/datatype/convertor.h"#include "ompi/datatype/datatype_internal.h"#include "ompi/datatype/datatype_checksum.h"#include "ompi/datatype/convertor_internal.h"static inline voidompi_dt_swap_bytes(void *to_p, const void *from_p, const size_t size){    size_t i, back_i;    uint8_t *to = (uint8_t*) to_p, *from = (uint8_t*) from_p;	back_i = size - 1;    for (i = 0 ; i < size ; i++, back_i--) {        to[back_i] = from[i];    }}#define COPY_TYPE_HETEROGENEOUS( TYPENAME, TYPE )                                         \static int32_t                                                                            \copy_##TYPENAME##_heterogeneous(ompi_convertor_t *pConvertor, uint32_t count,             \                                const char* from, size_t from_len, ptrdiff_t from_extent, \                                char* to, size_t to_length, ptrdiff_t to_extent,          \                                ptrdiff_t *advance)                     \{                                                                       \    uint32_t i;                                                         \                                                                        \    datatype_check( #TYPE, sizeof(TYPE), sizeof(TYPE), &count,          \                   from, from_len, from_extent,                         \                   to, to_length, to_extent);                           \                                                                        \    if ((pConvertor->remoteArch & OMPI_ARCH_ISBIGENDIAN) !=             \        (ompi_mpi_local_arch & OMPI_ARCH_ISBIGENDIAN)) {                \        for( i = 0; i < count; i++ ) {                                  \            ompi_dt_swap_bytes(to, from, sizeof(TYPE));                 \            to += to_extent;                                            \            from += from_extent;                                        \        }                                                               \    } else if ((ptrdiff_t)sizeof(TYPE) == to_extent &&                  \               (ptrdiff_t)sizeof(TYPE) == from_extent) {                \         MEMCPY( to, from, count * sizeof(TYPE) );                      \    } else {                                                            \         /* source or destination are non-contigous */                  \         for( i = 0; i < count; i++ ) {                                 \             MEMCPY( to, from, sizeof(TYPE) );                          \             to += to_extent;                                           \             from += from_extent;                                       \         }                                                              \    }                                                                   \    *advance = count * from_extent;                                     \    return count;                                                       \}#define COPY_2TYPE_HETEROGENEOUS( TYPENAME, TYPE1, TYPE2 )              \static int32_t                                                          \copy_##TYPENAME##_heterogeneous(ompi_convertor_t *pConvertor, uint32_t count, \                                const char* from, uint32_t from_len, ptrdiff_t from_extent, \                                char* to, uint32_t to_length, ptrdiff_t to_extent, \                                uint32_t *advance)                      \{                                                                       \    uint32_t i;                                                         \                                                                        \    datatype_check( #TYPENAME, sizeof(TYPE1) + sizeof(TYPE2),           \                   sizeof(TYPE1) + sizeof(TYPE2), &count,               \                   from, from_len, from_extent,                         \                   to, to_length, to_extent);                           \                                                                        \    if ((pConvertor->remoteArch & OMPI_ARCH_ISBIGENDIAN) !=             \        (ompi_mpi_local_arch & OMPI_ARCH_ISBIGENDIAN)) {                \        /* source and destination are different endianness */           \        for( i = 0; i < count; i++ ) {                                  \            TYPE1* to_1, *from_1;                                       \            TYPE2* to_2, *from_2;                                       \            to_1 = (TYPE1*) to; from_1 = (TYPE1*) from;                 \            ompi_dt_swap_bytes(to_1, from_1, sizeof(TYPE1));            \            to_2 = (TYPE2*) (to_1 + 1); from_2 = (TYPE2*) (from_1 + 1); \            ompi_dt_swap_bytes(to_2, from_2, sizeof(TYPE2));            \            to += to_extent;                                            \            from += from_extent;                                        \        }                                                               \    } else if ((ptrdiff_t)(sizeof(TYPE1) + sizeof(TYPE2)) == to_extent &&   \               (ptrdiff_t)(sizeof(TYPE1) + sizeof(TYPE2)) == from_extent) { \        /* source and destination are contigous */                      \        MEMCPY( to, from, count * (sizeof(TYPE1) + sizeof(TYPE2)) );    \    } else {                                                            \        /* source or destination are non-contigous */                   \        for( i = 0; i < count; i++ ) {                                  \            MEMCPY( to, from, sizeof(TYPE1) + sizeof(TYPE2) );          \            to += to_extent;                                            \            from += from_extent;                                        \        }                                                               \    }                                                                   \    *advance = count * from_extent;                                     \    return count;                                                       \}#define COPY_COMPLEX_HETEROGENEOUS( TYPENAME, TYPE )                    \    COPY_2TYPE_HETEROGENEOUS(complex_##TYPENAME, TYPE, TYPE)#define COPY_2COMPLEX_HETEROGENEOUS( TYPENAME, TYPE )                   \static int32_t                                                          \copy_2complex_##TYPENAME##_heterogeneous(ompi_convertor_t *pConvertor, uint32_t count, \                                         const char* from, uint32_t from_len, ptrdiff_t from_extent, \                                         char* to, uint32_t to_length, ptrdiff_t to_extent, \                                         uint32_t *advance)             \{                                                                       \    uint32_t i;                                                         \                                                                        \    datatype_check( #TYPENAME, sizeof(TYPE) * 2, sizeof(TYPE) * 2, &count, \                   from, from_len, from_extent,                         \                   to, to_length, to_extent);                           \                                                                        \    if ((pConvertor->remoteArch & OMPI_ARCH_ISBIGENDIAN) !=             \        (ompi_mpi_local_arch & OMPI_ARCH_ISBIGENDIAN)) {                \        /* source and destination are different endianness */           \        for( i = 0; i < count; i++ ) {                                  \            TYPE *to_p = (TYPE*) to, *from_p = (TYPE*) from;            \            ompi_dt_swap_bytes(&(to_p->r), &(from_p->r), sizeof(to_p->r)); \            ompi_dt_swap_bytes(&(to_p->i), &(from_p->i), sizeof(to_p->i)); \            to_p++; from_p++;                                           \            ompi_dt_swap_bytes(&(to_p->r), &(from_p->r), sizeof(to_p->r)); \            ompi_dt_swap_bytes(&(to_p->i), &(from_p->i), sizeof(to_p->i)); \            to += to_extent;                                            \            from += from_extent;                                        \        }                                                               \    } else if (sizeof(TYPE) * 2 == to_extent &&                         \               sizeof(TYPE) * 2 == from_extent) {                       \        /* source and destination are contigous */                      \        MEMCPY( to, from, count * (sizeof(TYPE) * 2) );                 \    } else {                                                            \        /* source or destination are non-contigous */                   \        for( i = 0; i < count; i++ ) {                                  \            MEMCPY( to, from, sizeof(TYPE) * 2 );                       \            to += to_extent;                                            \            from += from_extent;                                        \        }                                                               \    }                                                                   \    *advance = count * from_extent;                                     \    return count;                                                       \}static inline voiddatatype_check(char *type, size_t local_size, size_t remote_size, uint32_t *count,                const char* from, size_t from_len, ptrdiff_t from_extent,               char* to, size_t to_len, ptrdiff_t to_extent){    /* make sure the remote buffer is large enough to hold the data */      if( (remote_size * *count) > from_len ) {                               *count = (uint32_t)(from_len / remote_size);        if( (*count * remote_size) != from_len ) {                              DUMP( "oops should I keep this data somewhere (excedent %d bytes)?\n",                   from_len - (*count * remote_size) );                      }                                                                       DUMP( "correct: copy %s count %d from buffer %p with length %d to %p space %d\n",               "char", *count, from, from_len, to, to_len );                   } else {        DUMP( "         copy %s count %d from buffer %p with length %d to %p space %d\n",               "char", *count, from, from_len, to, to_len );                   }    }/* char has no endian issues, so don't really worry about it */static int32_t copy_char_heterogeneous(ompi_convertor_t *pConvertor, uint32_t count,                        const char* from, uint32_t from_len, ptrdiff_t from_extent,                        char* to, uint32_t to_length, ptrdiff_t to_extent,                        uint32_t *advance){    uint32_t i;    datatype_check("char", sizeof(char), sizeof(char), &count,                    from, from_len, from_extent,                   to, to_length, to_extent);    if( (from_extent == sizeof(char)) &&                               (to_extent == sizeof(char)) ) {                               /* copy of contigous data at both source and destination */     

⌨️ 快捷键说明

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