| 1 | /* -*- Mode: C; c-basic-offset:4 ; -*- */ |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | * (C) 2001 by Argonne National Laboratory. |
|---|
| 5 | * See COPYRIGHT in top-level directory. |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | #include "./dataloop.h" |
|---|
| 9 | |
|---|
| 10 | /*@ |
|---|
| 11 | Dataloop_contiguous - create the dataloop representation for a |
|---|
| 12 | contiguous datatype |
|---|
| 13 | |
|---|
| 14 | Arguments: |
|---|
| 15 | + int icount, |
|---|
| 16 | . MPI_Datatype oldtype, |
|---|
| 17 | . DLOOP_Dataloop **dlp_p, |
|---|
| 18 | . int *dlsz_p, |
|---|
| 19 | . int *dldepth_p, |
|---|
| 20 | - int flag |
|---|
| 21 | |
|---|
| 22 | .N Errors |
|---|
| 23 | .N Returns 0 on success, -1 on failure. |
|---|
| 24 | @*/ |
|---|
| 25 | int PREPEND_PREFIX(Dataloop_create_contiguous)(int icount, |
|---|
| 26 | DLOOP_Type oldtype, |
|---|
| 27 | DLOOP_Dataloop **dlp_p, |
|---|
| 28 | int *dlsz_p, |
|---|
| 29 | int *dldepth_p, |
|---|
| 30 | int flag) |
|---|
| 31 | { |
|---|
| 32 | DLOOP_Count count; |
|---|
| 33 | int is_builtin, apply_contig_coalescing = 0; |
|---|
| 34 | int new_loop_sz, new_loop_depth; |
|---|
| 35 | |
|---|
| 36 | DLOOP_Dataloop *new_dlp; |
|---|
| 37 | |
|---|
| 38 | count = (DLOOP_Count) icount; /* avoid subsequent casting */ |
|---|
| 39 | |
|---|
| 40 | is_builtin = (DLOOP_Handle_hasloop_macro(oldtype)) ? 0 : 1; |
|---|
| 41 | |
|---|
| 42 | if (is_builtin) |
|---|
| 43 | { |
|---|
| 44 | new_loop_depth = 1; |
|---|
| 45 | } |
|---|
| 46 | else |
|---|
| 47 | { |
|---|
| 48 | int old_loop_sz = 0, old_loop_depth = 0; |
|---|
| 49 | DLOOP_Offset old_size = 0, old_extent = 0; |
|---|
| 50 | DLOOP_Dataloop *old_loop_ptr; |
|---|
| 51 | |
|---|
| 52 | DLOOP_Handle_get_loopsize_macro(oldtype, old_loop_sz, flag); |
|---|
| 53 | DLOOP_Handle_get_loopdepth_macro(oldtype, old_loop_depth, flag); |
|---|
| 54 | DLOOP_Handle_get_loopptr_macro(oldtype, old_loop_ptr, flag); |
|---|
| 55 | DLOOP_Handle_get_size_macro(oldtype, old_size); |
|---|
| 56 | DLOOP_Handle_get_extent_macro(oldtype, old_extent); |
|---|
| 57 | |
|---|
| 58 | /* if we have a simple combination of contigs, coalesce */ |
|---|
| 59 | if (((old_loop_ptr->kind & DLOOP_KIND_MASK) == DLOOP_KIND_CONTIG) |
|---|
| 60 | && (old_size == old_extent)) |
|---|
| 61 | { |
|---|
| 62 | /* will just copy contig and multiply count */ |
|---|
| 63 | apply_contig_coalescing = 1; |
|---|
| 64 | new_loop_depth = old_loop_depth; |
|---|
| 65 | } |
|---|
| 66 | else |
|---|
| 67 | { |
|---|
| 68 | new_loop_depth = old_loop_depth + 1; |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | if (is_builtin) |
|---|
| 73 | { |
|---|
| 74 | DLOOP_Offset basic_sz = 0; |
|---|
| 75 | |
|---|
| 76 | PREPEND_PREFIX(Dataloop_alloc)(DLOOP_KIND_CONTIG, |
|---|
| 77 | count, |
|---|
| 78 | &new_dlp, |
|---|
| 79 | &new_loop_sz); |
|---|
| 80 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 81 | if (!new_dlp) return -1; |
|---|
| 82 | /* --END ERROR HANDLING-- */ |
|---|
| 83 | |
|---|
| 84 | DLOOP_Handle_get_size_macro(oldtype, basic_sz); |
|---|
| 85 | new_dlp->kind = DLOOP_KIND_CONTIG | DLOOP_FINAL_MASK; |
|---|
| 86 | |
|---|
| 87 | if (flag == DLOOP_DATALOOP_ALL_BYTES) |
|---|
| 88 | { |
|---|
| 89 | count *= basic_sz; |
|---|
| 90 | new_dlp->el_size = 1; |
|---|
| 91 | new_dlp->el_extent = 1; |
|---|
| 92 | new_dlp->el_type = MPI_BYTE; |
|---|
| 93 | } |
|---|
| 94 | else |
|---|
| 95 | { |
|---|
| 96 | new_dlp->el_size = basic_sz; |
|---|
| 97 | new_dlp->el_extent = new_dlp->el_size; |
|---|
| 98 | new_dlp->el_type = oldtype; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | new_dlp->loop_params.c_t.count = count; |
|---|
| 102 | } |
|---|
| 103 | else |
|---|
| 104 | { |
|---|
| 105 | /* user-defined base type (oldtype) */ |
|---|
| 106 | DLOOP_Dataloop *old_loop_ptr; |
|---|
| 107 | int old_loop_sz = 0; |
|---|
| 108 | |
|---|
| 109 | DLOOP_Handle_get_loopptr_macro(oldtype, old_loop_ptr, flag); |
|---|
| 110 | DLOOP_Handle_get_loopsize_macro(oldtype, old_loop_sz, flag); |
|---|
| 111 | |
|---|
| 112 | if (apply_contig_coalescing) |
|---|
| 113 | { |
|---|
| 114 | /* make a copy of the old loop and multiply the count */ |
|---|
| 115 | PREPEND_PREFIX(Dataloop_dup)(old_loop_ptr, |
|---|
| 116 | old_loop_sz, |
|---|
| 117 | &new_dlp); |
|---|
| 118 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 119 | if (!new_dlp) return -1; |
|---|
| 120 | /* --END ERROR HANDLING-- */ |
|---|
| 121 | |
|---|
| 122 | new_dlp->loop_params.c_t.count *= count; |
|---|
| 123 | |
|---|
| 124 | new_loop_sz = old_loop_sz; |
|---|
| 125 | DLOOP_Handle_get_loopdepth_macro(oldtype, new_loop_depth, flag); |
|---|
| 126 | } |
|---|
| 127 | else |
|---|
| 128 | { |
|---|
| 129 | /* allocate space for new loop including copy of old */ |
|---|
| 130 | PREPEND_PREFIX(Dataloop_alloc_and_copy)(DLOOP_KIND_CONTIG, |
|---|
| 131 | count, |
|---|
| 132 | old_loop_ptr, |
|---|
| 133 | old_loop_sz, |
|---|
| 134 | &new_dlp, |
|---|
| 135 | &new_loop_sz); |
|---|
| 136 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 137 | if (!new_dlp) return -1; |
|---|
| 138 | /* --END ERROR HANDLING-- */ |
|---|
| 139 | |
|---|
| 140 | new_dlp->kind = DLOOP_KIND_CONTIG; |
|---|
| 141 | DLOOP_Handle_get_size_macro(oldtype, new_dlp->el_size); |
|---|
| 142 | DLOOP_Handle_get_extent_macro(oldtype, new_dlp->el_extent); |
|---|
| 143 | DLOOP_Handle_get_basic_type_macro(oldtype, new_dlp->el_type); |
|---|
| 144 | |
|---|
| 145 | new_dlp->loop_params.c_t.count = count; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | *dlp_p = new_dlp; |
|---|
| 150 | *dlsz_p = new_loop_sz; |
|---|
| 151 | *dldepth_p = new_loop_depth; |
|---|
| 152 | |
|---|
| 153 | return 0; |
|---|
| 154 | } |
|---|