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

📄 dataloop_create_struct.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 2 页
字号:
	     *	     * optimization:	     *	     * push the count (blklen) from the struct down into the	     * contig so we can process more at the leaf.	     */	    err = PREPEND_PREFIX(Dataloop_create_contiguous)(blklens[i],							     oldtypes[i],							     &dummy_dlp,							     &dummy_sz,							     &dummy_depth,							     flag);	    	    /* --BEGIN ERROR HANDLING-- */	    if (err) {		/* TODO: FREE ALLOCATED RESOURCES */		return -1;	    }	    /* --END ERROR HANDLING-- */	    /* copy the new contig loop into place in the struct memory	     * region	     */	    PREPEND_PREFIX(Dataloop_copy)(curpos, dummy_dlp, dummy_sz);	    new_dlp->loop_params.s_t.dataloop_array[loop_idx] = curpos;	    curpos = (DLOOP_Dataloop *) ((char *) curpos + dummy_sz);	    /* we stored the block size in the contig -- use 1 here */	    new_dlp->loop_params.s_t.blocksize_array[loop_idx] = 1;	    new_dlp->loop_params.s_t.el_extent_array[loop_idx] =		((DLOOP_Offset) blklens[i]) * dummy_dlp->el_extent;	    PREPEND_PREFIX(Dataloop_free)(&dummy_dlp);	}	else	{	    DLOOP_Dataloop *old_loop_ptr;	    int old_loop_sz;	    DLOOP_Offset old_extent;	    DLOOP_Handle_get_loopptr_macro(oldtypes[i], old_loop_ptr, flag);	    DLOOP_Handle_get_loopsize_macro(oldtypes[i], old_loop_sz, flag);	    DLOOP_Handle_get_extent_macro(oldtypes[i], old_extent);	    PREPEND_PREFIX(Dataloop_copy)(curpos, old_loop_ptr, old_loop_sz);	    new_dlp->loop_params.s_t.dataloop_array[loop_idx] = curpos;	    curpos = (DLOOP_Dataloop *) ((char *) curpos + old_loop_sz);	    new_dlp->loop_params.s_t.blocksize_array[loop_idx] =		(DLOOP_Count) blklens[i];	    new_dlp->loop_params.s_t.el_extent_array[loop_idx] =		old_extent;	}	new_dlp->loop_params.s_t.offset_array[loop_idx] =	    (DLOOP_Offset) disps[i];	loop_idx++;    }    *dlp_p     = new_dlp;    *dlsz_p    = new_loop_sz;    *dldepth_p = new_loop_depth;    return 0;}/* --BEGIN ERROR HANDLING-- */static int DLOOP_Dataloop_create_struct_memory_error(void){    return -1;}/* --END ERROR HANDLING-- */static int DLOOP_Dataloop_create_unique_type_struct(int count,						    int *blklens,						    MPI_Aint *disps,						    DLOOP_Type *oldtypes,						    int type_pos,						    DLOOP_Dataloop **dlp_p,						    int *dlsz_p,						    int *dldepth_p,						    int flag){    /* the same type used more than once in the array; type_pos     * indexes to the first of these.     */    int i, err, *tmp_blklens, cur_pos = 0;    DLOOP_Offset *tmp_disps;    /* count is an upper bound on number of type instances */    tmp_blklens = (int *) DLOOP_Malloc(count * sizeof(int));    /* --BEGIN ERROR HANDLING-- */    if (!tmp_blklens) {	/* TODO: ??? */	return DLOOP_Dataloop_create_struct_memory_error();    }    /* --END ERROR HANDLING-- */    tmp_disps = (DLOOP_Offset *)	DLOOP_Malloc(count * sizeof(DLOOP_Offset));    /* --BEGIN ERROR HANDLING-- */    if (!tmp_disps) {	DLOOP_Free(tmp_blklens);	/* TODO: ??? */	return DLOOP_Dataloop_create_struct_memory_error();    }    /* --END ERROR HANDLING-- */    for (i=type_pos; i < count; i++)    {	if (oldtypes[i] == oldtypes[type_pos] && blklens != 0)	{	    tmp_blklens[cur_pos] = blklens[i];	    tmp_disps[cur_pos]   = disps[i];	    cur_pos++;	}    }    err = PREPEND_PREFIX(Dataloop_create_indexed)(cur_pos,						  tmp_blklens,						  tmp_disps,						  1, /* disp in bytes */						  oldtypes[type_pos],						  dlp_p,						  dlsz_p,						  dldepth_p,						  flag);    DLOOP_Free(tmp_blklens);    DLOOP_Free(tmp_disps);    return err;}static int DLOOP_Dataloop_create_basic_all_bytes_struct(	       int count,	       int *blklens,	       MPI_Aint *disps,	       DLOOP_Type *oldtypes,	       DLOOP_Dataloop **dlp_p,	       int *dlsz_p,	       int *dldepth_p,	       int flag){    int i, err, cur_pos = 0;    int *tmp_blklens;    MPI_Aint *tmp_disps;    /* count is an upper bound on number of type instances */    tmp_blklens = (int *) DLOOP_Malloc(count * sizeof(int));    /* --BEGIN ERROR HANDLING-- */    if (!tmp_blklens)    {	return DLOOP_Dataloop_create_struct_memory_error();    }    /* --END ERROR HANDLING-- */    tmp_disps = (MPI_Aint *) DLOOP_Malloc(count * sizeof(MPI_Aint));    /* --BEGIN ERROR HANDLING-- */    if (!tmp_disps)    {	DLOOP_Free(tmp_blklens);	return DLOOP_Dataloop_create_struct_memory_error();    }    /* --END ERROR HANDLING-- */    for (i=0; i < count; i++)    {	if (oldtypes[i] != MPI_LB && oldtypes[i] != MPI_UB && blklens[i] != 0)	{	    DLOOP_Offset sz;	    DLOOP_Handle_get_size_macro(oldtypes[i], sz);	    tmp_blklens[cur_pos] = (int) sz * blklens[i];	    tmp_disps[cur_pos]   = disps[i];	    cur_pos++;	}    }    err = PREPEND_PREFIX(Dataloop_create_indexed)(cur_pos,						  tmp_blklens,						  tmp_disps,						  1, /* disp in bytes */						  MPI_BYTE,						  dlp_p,						  dlsz_p,						  dldepth_p,						  flag);        DLOOP_Free(tmp_blklens);    DLOOP_Free(tmp_disps);    return err;}static int DLOOP_Dataloop_create_flattened_struct(int count,						  int *blklens,						  MPI_Aint *disps,						  DLOOP_Type *oldtypes,						  DLOOP_Dataloop **dlp_p,						  int *dlsz_p,						  int *dldepth_p,						  int flag){    /* arbitrary types, convert to bytes and use indexed */    int i, err, *tmp_blklens, nr_blks = 0;    MPI_Aint *tmp_disps; /* since we're calling another fn that takes			    this type as an input parameter */    DLOOP_Offset bytes;    DLOOP_Segment *segp;    int first_ind, last_ind;    segp = PREPEND_PREFIX(Segment_alloc)();    /* --BEGIN ERROR HANDLING-- */    if (!segp) {	return DLOOP_Dataloop_create_struct_memory_error();    }    /* --END ERROR HANDLING-- */    /* use segment code once to count contiguous regions */    for (i=0; i < count; i++)    {	int is_basic;	/* ignore type elements with a zero blklen */	if (blklens[i] == 0) continue;	is_basic = (DLOOP_Handle_hasloop_macro(oldtypes[i])) ? 0 : 1;	if (is_basic && (oldtypes[i] != MPI_LB &&			 oldtypes[i] != MPI_UB))	{	    nr_blks++;	}	else /* derived type; get a count of contig blocks */	{	    DLOOP_Count tmp_nr_blks;	    PREPEND_PREFIX(Segment_init)(NULL,					 (DLOOP_Count) blklens[i],					 oldtypes[i],					 segp,					 flag);	    bytes = SEGMENT_IGNORE_LAST;	    PREPEND_PREFIX(Segment_count_contig_blocks)(segp,							0,							&bytes,							&tmp_nr_blks);	    nr_blks += tmp_nr_blks;	}    }    nr_blks += 2; /* safety measure */    tmp_blklens = (int *) DLOOP_Malloc(nr_blks * sizeof(int));    /* --BEGIN ERROR HANDLING-- */    if (!tmp_blklens) {	return DLOOP_Dataloop_create_struct_memory_error();    }    /* --END ERROR HANDLING-- */    tmp_disps = (MPI_Aint *) DLOOP_Malloc(nr_blks * sizeof(MPI_Aint));    /* --BEGIN ERROR HANDLING-- */    if (!tmp_disps) {	DLOOP_Free(tmp_blklens);	return DLOOP_Dataloop_create_struct_memory_error();    }    /* --END ERROR HANDLING-- */    /* use segment code again to flatten the type */    first_ind = 0;    for (i=0; i < count; i++)    {	/* we're going to use the segment code to flatten the type.	 * we put in our displacement as the buffer location, and use	 * the blocklength as the count value to get N contiguous copies	 * of the type.	 *	 * Note that we're going to get back values in bytes, so that will	 * be our new element type.	 */	if (oldtypes[i] != MPI_UB && oldtypes[i] != MPI_LB && blklens[i] != 0)	{	    PREPEND_PREFIX(Segment_init)((char *) disps[i],					 (DLOOP_Count) blklens[i],					 oldtypes[i],					 segp,					 0 /* homogeneous */);	    	    last_ind = nr_blks - first_ind;	    bytes = SEGMENT_IGNORE_LAST;	    PREPEND_PREFIX(Segment_mpi_flatten)(segp,						0,						&bytes,						&tmp_blklens[first_ind],						&tmp_disps[first_ind],						&last_ind);	    first_ind += last_ind;	}    }    nr_blks = first_ind;#if 0    if (MPIU_DBG_SELECTED(DATATYPE,VERBOSE)) {	MPIU_DBG_OUT(DATATYPE,"--- start of flattened type ---");        for (i=0; i < nr_blks; i++) {	MPIU_DBG_OUT_FMT(DATATYPE,(MPIU_DBG_FDEST,				   "a[%d] = (%d, %d)\n", i,				   tmp_blklens[i], tmp_disps[i]));	}	MPIU_DBG_OUT(DATATYPE,"--- end of flattened type ---");    }#endif    PREPEND_PREFIX(Segment_free)(segp);    err = PREPEND_PREFIX(Dataloop_create_indexed)(nr_blks,						  tmp_blklens,						  tmp_disps,						  1, /* disp in bytes */						  MPI_BYTE,						  dlp_p,						  dlsz_p,						  dldepth_p,						  flag);        DLOOP_Free(tmp_blklens);    DLOOP_Free(tmp_disps);    return err;}

⌨️ 快捷键说明

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