00001
00002
00003
00004
00005
00006
00007
00008 #include "./dataloop.h"
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 int PREPEND_PREFIX(Dataloop_create_vector)(int icount,
00028 int iblocklength,
00029 MPI_Aint astride,
00030 int strideinbytes,
00031 DLOOP_Type oldtype,
00032 DLOOP_Dataloop **dlp_p,
00033 int *dlsz_p,
00034 int *dldepth_p,
00035 int flag)
00036 {
00037 int err, is_builtin;
00038 int new_loop_sz, new_loop_depth;
00039
00040 DLOOP_Count count, blocklength;
00041 DLOOP_Offset stride;
00042 DLOOP_Dataloop *new_dlp;
00043
00044 count = (DLOOP_Count) icount;
00045 blocklength = (DLOOP_Count) iblocklength;
00046 stride = (DLOOP_Offset) astride;
00047
00048
00049
00050
00051 if (count == 0 || blocklength == 0)
00052 {
00053
00054 err = PREPEND_PREFIX(Dataloop_create_contiguous)(0,
00055 MPI_INT,
00056 dlp_p,
00057 dlsz_p,
00058 dldepth_p,
00059 flag);
00060 return err;
00061 }
00062
00063
00064
00065
00066
00067 if (count == 1) {
00068 err = PREPEND_PREFIX(Dataloop_create_contiguous)(iblocklength,
00069 oldtype,
00070 dlp_p,
00071 dlsz_p,
00072 dldepth_p,
00073 flag);
00074 return err;
00075 }
00076
00077 is_builtin = (DLOOP_Handle_hasloop_macro(oldtype)) ? 0 : 1;
00078
00079 if (is_builtin) {
00080 new_loop_sz = sizeof(DLOOP_Dataloop);
00081 new_loop_depth = 1;
00082 }
00083 else {
00084 int old_loop_sz = 0, old_loop_depth = 0;
00085
00086 DLOOP_Handle_get_loopsize_macro(oldtype, old_loop_sz, flag);
00087 DLOOP_Handle_get_loopdepth_macro(oldtype, old_loop_depth, flag);
00088
00089
00090 new_loop_sz = sizeof(DLOOP_Dataloop) + old_loop_sz;
00091 new_loop_depth = old_loop_depth + 1;
00092 }
00093
00094
00095 if (is_builtin) {
00096 DLOOP_Offset basic_sz = 0;
00097
00098 PREPEND_PREFIX(Dataloop_alloc)(DLOOP_KIND_VECTOR,
00099 count,
00100 &new_dlp,
00101 &new_loop_sz);
00102
00103 if (!new_dlp) return -1;
00104
00105
00106 DLOOP_Handle_get_size_macro(oldtype, basic_sz);
00107 new_dlp->kind = DLOOP_KIND_VECTOR | DLOOP_FINAL_MASK;
00108
00109 if (flag == DLOOP_DATALOOP_ALL_BYTES)
00110 {
00111
00112 blocklength *= basic_sz;
00113 new_dlp->el_size = 1;
00114 new_dlp->el_extent = 1;
00115 new_dlp->el_type = MPI_BYTE;
00116 }
00117 else
00118 {
00119 new_dlp->el_size = basic_sz;
00120 new_dlp->el_extent = new_dlp->el_size;
00121 new_dlp->el_type = oldtype;
00122 }
00123 }
00124 else {
00125 DLOOP_Dataloop *old_loop_ptr;
00126 int old_loop_sz = 0;
00127
00128 DLOOP_Handle_get_loopptr_macro(oldtype, old_loop_ptr, flag);
00129 DLOOP_Handle_get_loopsize_macro(oldtype, old_loop_sz, flag);
00130
00131 PREPEND_PREFIX(Dataloop_alloc_and_copy)(DLOOP_KIND_VECTOR,
00132 count,
00133 old_loop_ptr,
00134 old_loop_sz,
00135 &new_dlp,
00136 &new_loop_sz);
00137
00138 if (!new_dlp) return -1;
00139
00140
00141 new_dlp->kind = DLOOP_KIND_VECTOR;
00142 DLOOP_Handle_get_size_macro(oldtype, new_dlp->el_size);
00143 DLOOP_Handle_get_extent_macro(oldtype, new_dlp->el_extent);
00144 DLOOP_Handle_get_basic_type_macro(oldtype, new_dlp->el_type);
00145 }
00146
00147
00148
00149
00150
00151 new_dlp->loop_params.v_t.count = count;
00152 new_dlp->loop_params.v_t.blocksize = blocklength;
00153 new_dlp->loop_params.v_t.stride = (strideinbytes) ? stride :
00154 stride * new_dlp->el_extent;
00155
00156 *dlp_p = new_dlp;
00157 *dlsz_p = new_loop_sz;
00158 *dldepth_p = new_loop_depth;
00159
00160 return 0;
00161 }