📄 mpid_segment.c
字号:
paramp->u.pack_vector.vectorp[last_idx].DLOOP_VECTOR_LEN += size; } else { paramp->u.pack_vector.vectorp[last_idx+1].DLOOP_VECTOR_BUF = (char *) bufp + rel_off; paramp->u.pack_vector.vectorp[last_idx+1].DLOOP_VECTOR_LEN = size; paramp->u.pack_vector.index++; } MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_CONTIG_PACK_TO_IOV); return 0;}#undef FUNCNAME#define FUNCNAME MPID_Segment_vector_pack_to_iov#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)/* MPID_Segment_vector_pack_to_iov * * Input Parameters: * blocks_p - [inout] pointer to a count of blocks (total, for all noncontiguous pieces) * count - # of noncontiguous regions * blksz - size of each noncontiguous region * stride - distance in bytes from start of one region to start of next * el_type - elemental type (e.g. MPI_INT) * ... * * Note: this is only called when the starting position is at the beginning * of a whole block in a vector type. */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, /* offset into buffer */ void *bufp, /* start of buffer */ void *v_paramp){ int i, basic_size; DLOOP_Offset size, blocks_left; struct MPID_Segment_piece_params *paramp = v_paramp; MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_VECTOR_PACK_TO_IOV); MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_VECTOR_PACK_TO_IOV); basic_size = MPID_Datatype_get_basic_size(el_type); blocks_left = *blocks_p; MPIU_DBG_MSG_FMT(DATATYPE,VERBOSE,(MPIU_DBG_FDEST, "\t[vector to vec: do=%d" ", dp=" MPI_AINT_FMT_HEX_SPEC ", len=%d, ind=%d, ct=%d, blksz=%d" ", str=" MPI_AINT_FMT_DEC_SPEC ", blks=" MPI_AINT_FMT_DEC_SPEC "]\n", (unsigned) rel_off, (MPI_Aint)bufp, paramp->u.pack_vector.length, paramp->u.pack_vector.index, count, blksz, stride, *blocks_p)); for (i=0; i < count && blocks_left > 0; i++) { int last_idx; char *last_end = NULL; if (blocks_left > blksz) { size = blksz * basic_size; blocks_left -= blksz; } else { /* last pass */ size = blocks_left * basic_size; blocks_left = 0; } last_idx = paramp->u.pack_vector.index - 1; if (last_idx >= 0) { last_end = ((char *) paramp->u.pack_vector.vectorp[last_idx].DLOOP_VECTOR_BUF) + paramp->u.pack_vector.vectorp[last_idx].DLOOP_VECTOR_LEN; } if ((last_idx == paramp->u.pack_vector.length-1) && (last_end != ((char *) bufp + rel_off))) { /* we have used up all our entries, and this one doesn't fit on * the end of the last one. */ *blocks_p -= (blocks_left + (size / basic_size));#if 0 paramp->u.pack_vector.index++;#endif#ifdef MPID_SP_VERBOSE MPIU_dbg_printf("\t[vector to vec exiting (1): next ind = %d, %d blocks processed.\n", paramp->u.pack_vector.index, (int) *blocks_p);#endif MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_VECTOR_PACK_TO_IOV); return 1; } else if (last_idx >= 0 && (last_end == ((char *) bufp + rel_off))) { /* add this size to the last vector rather than using up new one */ paramp->u.pack_vector.vectorp[last_idx].DLOOP_VECTOR_LEN += size; } else { paramp->u.pack_vector.vectorp[last_idx+1].DLOOP_VECTOR_BUF = (char *) bufp + rel_off; paramp->u.pack_vector.vectorp[last_idx+1].DLOOP_VECTOR_LEN = size; paramp->u.pack_vector.index++; } rel_off += stride; }#ifdef MPID_SP_VERBOSE MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, %d blocks processed.\n", paramp->u.pack_vector.index, (int) *blocks_p);#endif /* if we get here then we processed ALL the blocks; don't need to update * blocks_p */ MPIU_Assert(blocks_left == 0); MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_VECTOR_PACK_TO_IOV); return 0;}/********** FUNCTIONS FOR FLATTENING A TYPE **********/#undef FUNCNAME#define FUNCNAME MPID_Segment_contig_flatten#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)/* MPID_Segment_contig_flatten */static int MPID_Segment_contig_flatten(DLOOP_Offset *blocks_p, DLOOP_Type el_type, DLOOP_Offset rel_off, void *bufp, void *v_paramp){ int index, el_size; DLOOP_Offset size; struct MPID_Segment_piece_params *paramp = v_paramp; MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_CONTIG_FLATTEN); MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_CONTIG_FLATTEN); el_size = MPID_Datatype_get_basic_size(el_type); size = *blocks_p * (DLOOP_Offset) el_size; index = paramp->u.flatten.index;#ifdef MPID_SP_VERBOSE MPIU_dbg_printf("\t[contig flatten: index = %d, loc = (%x + %x) = %x, size = %d]\n", index, (unsigned) bufp, (unsigned) rel_off, (unsigned) bufp + rel_off, (int) size);#endif if (index > 0 && ((DLOOP_Offset) bufp + rel_off) == ((paramp->u.flatten.offp[index - 1]) + (DLOOP_Offset) paramp->u.flatten.sizep[index - 1])) { /* add this size to the last vector rather than using up another one */ paramp->u.flatten.sizep[index - 1] += size; } else { paramp->u.flatten.offp[index] = ((int64_t) (MPI_Aint) bufp) + (int64_t) rel_off; paramp->u.flatten.sizep[index] = size; paramp->u.flatten.index++; /* check to see if we have used our entire vector buffer, and if so * return 1 to stop processing */ if (paramp->u.flatten.index == paramp->u.flatten.length) { MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_CONTIG_FLATTEN); return 1; } } MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_CONTIG_FLATTEN); return 0;}#undef FUNCNAME#define FUNCNAME MPID_Segment_vector_flatten#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)/* MPID_Segment_vector_flatten * * Notes: * - this is only called when the starting position is at the beginning * of a whole block in a vector type. * - this was a virtual copy of MPID_Segment_pack_to_iov; now it has improvements * that MPID_Segment_pack_to_iov needs. * - we return the number of blocks that we did process in region pointed to by * blocks_p. */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){ int i, basic_size; DLOOP_Offset size, blocks_left; struct MPID_Segment_piece_params *paramp = v_paramp; MPIDI_STATE_DECL(MPID_STATE_MPID_SEGMENT_VECTOR_FLATTEN); MPIDI_FUNC_ENTER(MPID_STATE_MPID_SEGMENT_VECTOR_FLATTEN); basic_size = MPID_Datatype_get_basic_size(el_type); blocks_left = *blocks_p; for (i=0; i < count && blocks_left > 0; i++) { int index = paramp->u.flatten.index; if (blocks_left > blksz) { size = blksz * (DLOOP_Offset) basic_size; blocks_left -= blksz; } else { /* last pass */ size = blocks_left * basic_size; blocks_left = 0; } if (index > 0 && ((DLOOP_Offset) bufp + rel_off) == ((paramp->u.flatten.offp[index - 1]) + (DLOOP_Offset) paramp->u.flatten.sizep[index - 1])) { /* add this size to the last region rather than using up another one */ paramp->u.flatten.sizep[index - 1] += size; } else if (index < paramp->u.flatten.length) { /* take up another region */ paramp->u.flatten.offp[index] = (DLOOP_Offset) bufp + rel_off; paramp->u.flatten.sizep[index] = size; paramp->u.flatten.index++; } else { /* we tried to add to the end of the last region and failed; add blocks back in */ *blocks_p = *blocks_p - blocks_left + (size / basic_size); MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_VECTOR_FLATTEN); return 1; } rel_off += stride; } /* --BEGIN ERROR HANDLING-- */ MPIU_Assert(blocks_left == 0); /* --END ERROR HANDLING-- */ MPIDI_FUNC_EXIT(MPID_STATE_MPID_SEGMENT_VECTOR_FLATTEN); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -