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

📄 mpid_segment.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
📖 第 1 页 / 共 3 页
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* *  (C) 2001 by Argonne National Laboratory. *      See COPYRIGHT in top-level directory. */#include <stdio.h>#include <stdlib.h>#include <mpiimpl.h>#include <mpid_dataloop.h>#undef MPID_SP_VERBOSE#undef MPID_SU_VERBOSE/* MPID_Segment_piece_params * * This structure is used to pass function-specific parameters into our  * segment processing function.  This allows us to get additional parameters * to the functions it calls without changing the prototype. */struct MPID_Segment_piece_params {    union {        struct {            char *pack_buffer;        } pack;        struct {            DLOOP_VECTOR *vectorp;            int index;            int length;        } pack_vector;        struct {	    int64_t *offp;	    int *sizep; /* see notes in Segment_flatten header */            int index;            int length;        } flatten;	struct {	    char *last_loc;	    int count;	} contig_blocks;        struct {            char *unpack_buffer;        } unpack;        struct {            int stream_off;        } print;    } u;};#define MPIDI_COPY_FROM_VEC(src,dest,stride,type,nelms,count)	\{								\    type * l_src = (type *)src, * l_dest = (type *)dest;	\    int i, j;							\    const int l_stride = stride;				\    if (nelms == 1) {						\        for (i=count;i!=0;i--) {				\            *l_dest++ = *l_src;					\            l_src = (type *) ((char *) l_src + l_stride);	\        }							\    }								\    else {							\        for (i=count; i!=0; i--) {				\            for (j=0; j<nelms; j++) {				\                *l_dest++ = l_src[j];				\	    }							\            l_src = (type *) ((char *) l_src + l_stride);	\        }							\    }								\    dest = (char *) l_dest;					\    src  = (char *) l_src;                                      \}#define MPIDI_COPY_TO_VEC(src,dest,stride,type,nelms,count)	\{								\    type * l_src = (type *)src, * l_dest = (type *)dest;	\    int i, j;							\    const int l_stride = stride;				\    if (nelms == 1) {						\        for (i=count;i!=0;i--) {				\            *l_dest = *l_src++;					\            l_dest = (type *) ((char *) l_dest + l_stride);	\        }							\    }								\    else {							\        for (i=count; i!=0; i--) {				\            for (j=0; j<nelms; j++) {				\                l_dest[j] = *l_src++;				\	    }							\            l_dest = (type *) ((char *) l_dest + l_stride);	\        }							\    }								\    dest = (char *) l_dest;					\    src  = (char *) l_src;                                      \}/* prototypes of internal functions */static int MPID_Segment_vector_pack_to_iov(DLOOP_Offset *blocks_p,					   int count,					   int blksz,					   DLOOP_Offset stride,					   DLOOP_Type el_type,					   DLOOP_Offset rel_off,					   void *bufp,					   void *v_paramp);static int MPID_Segment_contig_pack_to_iov(DLOOP_Offset *blocks_p,					   DLOOP_Type el_type,					   DLOOP_Offset rel_off,					   void *bufp,					   void *v_paramp);static int MPID_Segment_contig_unpack_to_buf(DLOOP_Offset *blocks_p,                                             DLOOP_Type el_type,					     DLOOP_Offset rel_off,					     void *bufp,					     void *v_paramp);static int MPID_Segment_index_unpack_to_buf(DLOOP_Offset *blocks_p,					    int count,					    int *blockarray,					    DLOOP_Offset *offsetarray,                                            DLOOP_Type el_type,					    DLOOP_Offset rel_off,					    void *bufp,					    void *v_paramp);static int MPID_Segment_blkidx_unpack_to_buf(DLOOP_Offset *blocks_p,					     int count,					     int blocklen,					     DLOOP_Offset *offsetarray,					     DLOOP_Type el_type,					     DLOOP_Offset rel_off,					     void *bufp,					     void *v_paramp);static int MPID_Segment_blkidx_pack_to_buf(DLOOP_Offset *blocks_p,					   int count,					   int blocklen,					   DLOOP_Offset *offsetarray,					   DLOOP_Type el_type,					   DLOOP_Offset rel_off,					   void *bufp,					   void *v_paramp);static int MPID_Segment_index_pack_to_buf(DLOOP_Offset *blocks_p,					  int count,					  int *blockarray,					  DLOOP_Offset *offsetarray,                                          DLOOP_Type el_type,					  DLOOP_Offset rel_off,					  void *bufp,					  void *v_paramp);static int MPID_Segment_vector_pack_to_buf(DLOOP_Offset *blocks_p,					   int count,					   int blksz,					   DLOOP_Offset stride,                                           DLOOP_Type el_type,					   DLOOP_Offset rel_off,					   void *bufp,					   void *v_paramp);static int MPID_Segment_vector_unpack_to_buf(DLOOP_Offset *blocks_p,					     int count,					     int blksz,					     DLOOP_Offset stride,                                             DLOOP_Type el_type,					     DLOOP_Offset rel_off,					     void *bufp,					     void *v_paramp);static int MPID_Segment_contig_pack_to_buf(DLOOP_Offset *blocks_p,                                           DLOOP_Type el_type,					   DLOOP_Offset rel_off,					   void *bufp,					   void *v_paramp);static int MPID_Segment_contig_count_block(DLOOP_Offset *blocks_p,                                           DLOOP_Type el_type,					   DLOOP_Offset rel_off,					   void *bufp,					   void *v_paramp);static int MPID_Segment_contig_flatten(DLOOP_Offset *blocks_p,                                       DLOOP_Type el_type,				       DLOOP_Offset rel_off,				       void *bufp,				       void *v_paramp);static int MPID_Segment_vector_flatten(DLOOP_Offset *blocks_p,				       int count,				       int blksz,				       DLOOP_Offset stride,                                       DLOOP_Type el_type,				       DLOOP_Offset rel_off, /* offset into buffer */				       void *bufp, /* start of buffer */				       void *v_paramp);/********** EXTERNALLY VISIBLE FUNCTIONS FOR TYPE MANIPULATION **********/#undef FUNCNAME#define FUNCNAME MPID_Segment_pack#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)/* Segment_pack - we need to implement this if for no other reason * than for performance testing * * Input Parameters: * segp - pointer to segment * pack_buffer - pointer to buffer to pack into * first - first byte index to be packed (or actually packed (?)) * * InOut Parameters: * last - pointer to last byte index to be packed plus 1 (makes math easier) * * This and the similar functions all set up a piece_params structure that * they then pass to MPID_Segment_manipulate along with the function that  * they want called on each piece.  So in this case MPID_Segment_manipulate * will call MPID_Segment_piece_pack() on each piece of the buffer to pack, * where a piece is a basic datatype. * * Eventually we'll probably ditch this approach to gain some speed, but * for now it lets me have one function (_manipulate) that implements our * algorithm for parsing. * */void MPID_Segment_pack(struct DLOOP_Segment *segp,		       DLOOP_Offset first,		       DLOOP_Offset *lastp, 		       void *pack_buffer){    struct MPID_Segment_piece_params pack_params;    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_PACK);        MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_PACK);    pack_params.u.pack.pack_buffer = pack_buffer;    MPID_Segment_manipulate(segp,			    first,			    lastp,			    MPID_Segment_contig_pack_to_buf, 			    MPID_Segment_vector_pack_to_buf,			    MPID_Segment_blkidx_pack_to_buf,			    MPID_Segment_index_pack_to_buf,                            NULL,			    &pack_params);    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_PACK);    return;}/* Segment_unpack */#undef FUNCNAME#define FUNCNAME MPID_Segment_unpack#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)void MPID_Segment_unpack(struct DLOOP_Segment *segp,			 DLOOP_Offset first,			 DLOOP_Offset *lastp,			 const DLOOP_Buffer unpack_buffer){    struct MPID_Segment_piece_params unpack_params;    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_UNPACK);    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_UNPACK);    unpack_params.u.unpack.unpack_buffer = (DLOOP_Buffer) unpack_buffer;    MPID_Segment_manipulate(segp,			    first,			    lastp, 			    MPID_Segment_contig_unpack_to_buf,			    MPID_Segment_vector_unpack_to_buf,			    MPID_Segment_blkidx_unpack_to_buf,			    MPID_Segment_index_unpack_to_buf,                            NULL,			    &unpack_params);    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_UNPACK);    return;}#undef FUNCNAME#define FUNCNAME MPID_Segment_pack_vector#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)/* MPID_Segment_pack_vector * * Parameters: * segp    - pointer to segment structure * first   - first byte in segment to pack * lastp   - in/out parameter describing last byte to pack (and afterwards *           the last byte _actually_ packed) *           NOTE: actually returns index of byte _after_ last one packed * vectorp - pointer to (off, len) pairs to fill in * lengthp - in/out parameter describing length of array (and afterwards *           the amount of the array that has actual data) */void MPID_Segment_pack_vector(struct DLOOP_Segment *segp,			      DLOOP_Offset first,			      DLOOP_Offset *lastp,			      DLOOP_VECTOR *vectorp,			      int *lengthp){    struct MPID_Segment_piece_params packvec_params;    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_PACK_VECTOR);    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_PACK_VECTOR);    packvec_params.u.pack_vector.vectorp = vectorp;    packvec_params.u.pack_vector.index   = 0;    packvec_params.u.pack_vector.length  = *lengthp;    MPIU_Assert(*lengthp > 0);    MPID_Segment_manipulate(segp,			    first,			    lastp, 			    MPID_Segment_contig_pack_to_iov, 			    MPID_Segment_vector_pack_to_iov,			    NULL, /* blkidx fn */			    NULL, /* index fn */                            NULL,			    &packvec_params);    /* last value already handled by MPID_Segment_manipulate */    *lengthp = packvec_params.u.pack_vector.index;    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_PACK_VECTOR);    return;}/* MPID_Segment_unpack_vector * * Q: Should this be any different from pack vector? */#undef FUNCNAME#define FUNCNAME MPID_Segment_unpack_vector#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)void MPID_Segment_unpack_vector(struct DLOOP_Segment *segp,				DLOOP_Offset first,				DLOOP_Offset *lastp,				DLOOP_VECTOR *vectorp,				int *lengthp){    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_UNPACK_VECTOR);    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_UNPACK_VECTOR);    MPID_Segment_pack_vector(segp, first, lastp, vectorp, lengthp);    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_UNPACK_VECTOR);    return;}#undef FUNCNAME#define FUNCNAME MPID_Segment_flatten#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)/* MPID_Segment_flatten * * offp    - pointer to array to fill in with offsets * sizep   - pointer to array to fill in with sizes * lengthp - pointer to value holding size of arrays; # used is returned * * Internally, index is used to store the index of next array value to fill in. * * TODO: MAKE SIZES Aints IN ROMIO, CHANGE THIS TO USE INTS TOO. */void MPID_Segment_flatten(struct DLOOP_Segment *segp,			  DLOOP_Offset first,			  DLOOP_Offset *lastp,			  DLOOP_Offset *offp,			  int *sizep,			  DLOOP_Offset *lengthp){    struct MPID_Segment_piece_params packvec_params;    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_FLATTEN);    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_FLATTEN);    packvec_params.u.flatten.offp = (int64_t *) offp;    packvec_params.u.flatten.sizep = sizep;    packvec_params.u.flatten.index   = 0;    packvec_params.u.flatten.length  = *lengthp;    MPIU_Assert(*lengthp > 0);    MPID_Segment_manipulate(segp,			    first,			    lastp, 			    MPID_Segment_contig_flatten, 			    MPID_Segment_vector_flatten,			    NULL, /* blkidx fn */			    NULL,                            NULL,			    &packvec_params);    /* last value already handled by MPID_Segment_manipulate */    *lengthp = packvec_params.u.flatten.index;    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_FLATTEN);    return;}#undef FUNCNAME#define FUNCNAME MPID_Segment_count_contig_blocks#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)/* MPID_Segment_count_contig_blocks() * * Count number of contiguous regions in segment between first and last. */void MPID_Segment_count_contig_blocks(struct DLOOP_Segment *segp,				      DLOOP_Offset first,				      DLOOP_Offset *lastp,				      int *countp){    struct MPID_Segment_piece_params packvec_params;    MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_COUNT_CONTIG_BLOCKS);    MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_COUNT_CONTIG_BLOCKS);    packvec_params.u.contig_blocks.last_loc = NULL;    packvec_params.u.contig_blocks.count    = 0;    MPID_Segment_manipulate(segp,			    first,			    lastp,			    MPID_Segment_contig_count_block,			    NULL, /* vector fn */			    NULL, /* blkidx fn */			    NULL, /* index fn */                            NULL, /* size fn */			    &packvec_params);    *countp = packvec_params.u.contig_blocks.count;    MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_COUNT_CONTIG_BLOCKS);}

⌨️ 快捷键说明

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