| 1 |
|
| /* XXX NOTE THAT IT IS NOT SAFE TO USE ->pdls MEMBER OUTSIDE |
| 2 |
|
| INITBROADCASTSTRUCT! */ |
| 3 |
|
| |
| 4 |
|
| #include "pdl.h" /* Data structure declarations */ |
| 5 |
|
| #include "pdlcore.h" /* Core declarations */ |
| 6 |
|
| |
| 7 |
|
| #define MAX2(a,b) if ((b)>(a)) a=b; |
| 8 |
|
| |
| 9 |
|
| /**** Convenience routines for moving around collections |
| 10 |
|
| **** of indices and PDL pointers. |
| 11 |
|
| ****/ |
| 12 |
38029 |
| static pdl **copy_pdl_array (pdl **from, int size) { |
| 13 |
|
| pdl **to; |
| 14 |
38029 |
| Newx (to, size, pdl*); |
| 15 |
38029 |
| return (pdl **) CopyD (from, to, size, pdl*); |
| 16 |
|
| } |
| 17 |
|
| |
| 18 |
|
| /******* |
| 19 |
|
| * pdl_get_broadcastdims - get the pthread-specific broadcasting dims from a PDL |
| 20 |
|
| * Input: broadcast structure |
| 21 |
|
| * Outputs: see above (returned by function) |
| 22 |
|
| */ |
| 23 |
91452 |
| PDL_Indx *pdl_get_broadcastdims(pdl_broadcast *broadcast) |
| 24 |
|
| { |
| 25 |
|
| /* The non-multithreaded case: return just the usual value */ |
| 26 |
91452 |
▶ | if (!(broadcast->gflags & PDL_BROADCAST_MAGICKED)) return broadcast->dims; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(broadcast->gflags & PDL_BROADCAST_MAGICKED)) return broadcast->dims; |
90619 |
833 |
91452 |
|
| 27 |
833 |
| int thr = pdl_magic_get_thread(broadcast->pdls[broadcast->mag_nthpdl]); |
| 28 |
833 |
▶ | if (thr < 0) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (thr < 0) return NULL; |
0 |
833 |
833 |
|
| 29 |
833 |
| return broadcast->dims + thr * broadcast->ndims; |
| 30 |
|
| } |
| 31 |
|
| |
| 32 |
|
| |
| 33 |
|
| /******* |
| 34 |
|
| * pdl_get_threadoffsp - get the pthread-specific offset arrays from a PDL |
| 35 |
|
| * Input: broadcast structure |
| 36 |
|
| * Outputs: Pointer to pthread-specific offset array (returned by function) |
| 37 |
|
| */ |
| 38 |
91452 |
| PDL_Indx *pdl_get_threadoffsp(pdl_broadcast *broadcast) |
| 39 |
|
| { |
| 40 |
|
| /* The non-multithreaded case: return just the usual offsets */ |
| 41 |
91452 |
▶ | if (!(broadcast->gflags & PDL_BROADCAST_MAGICKED)) return broadcast->offs; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(broadcast->gflags & PDL_BROADCAST_MAGICKED)) return broadcast->offs; |
90619 |
833 |
91452 |
|
| 42 |
833 |
| int thr = pdl_magic_get_thread(broadcast->pdls[broadcast->mag_nthpdl]); |
| 43 |
834 |
▶ | if (thr < 0) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (thr < 0) return NULL; |
0 |
834 |
834 |
|
| 44 |
834 |
| return broadcast->offs + thr * broadcast->npdls; |
| 45 |
|
| } |
| 46 |
|
| |
| 47 |
|
| |
| 48 |
|
| /* Function to get the pthread-specific offset, indexes and pthread number for the supplied broadcast structure |
| 49 |
|
| Input: broadcast structure |
| 50 |
|
| Outputs: Pointer to pthread-specific offset array (returned by function) |
| 51 |
|
| Pointer to pthread-specific index array (ind Pointer supplied and modified by function) |
| 52 |
|
| Pointer to pthread-specific dims array (dims Pointer supplied and modified by function) |
| 53 |
|
| Pthread index for the current pthread ( thr supplied and modified by function) |
| 54 |
|
| */ |
| 55 |
135543 |
| static inline PDL_Indx* pdl_get_threadoffsp_int(pdl_broadcast *broadcast, int *pthr, PDL_Indx **inds, PDL_Indx **dims) |
| 56 |
|
| { |
| 57 |
135543 |
▶ | if (broadcast->gflags & PDL_BROADCAST_MAGICKED) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->gflags & PDL_BROADCAST_MAGICKED) { |
1405 |
134138 |
135543 |
|
| 58 |
1405 |
▶ | if (broadcast->mag_nthpdl < 0 || broadcast->mag_nthpdl >= broadcast->npdls) |
Branch: 2 branches
| Branch | True | False | Total |
| if (broadcast->mag_nthpdl < 0 || broadcast->mag_nthpdl >= broadcast->npdls) |
1405 |
0 |
1405 |
| if (broadcast->mag_nthpdl < 0 || broadcast->mag_nthpdl >= broadcast->npdls) |
0 |
1405 |
1405 |
|
| 59 |
0 |
| return NULL; |
| 60 |
1405 |
| int thr = pdl_magic_get_thread(broadcast->pdls[broadcast->mag_nthpdl]); |
| 61 |
1405 |
▶ | if (thr < 0) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (thr < 0) return NULL; |
0 |
1405 |
1405 |
|
| 62 |
1405 |
| *pthr = thr; |
| 63 |
1405 |
| *inds = broadcast->inds + thr * broadcast->ndims; |
| 64 |
1405 |
| *dims = broadcast->dims + thr * broadcast->ndims; |
| 65 |
1405 |
| return broadcast->offs + thr * broadcast->npdls; |
| 66 |
|
| } |
| 67 |
134138 |
| *pthr = 0; |
| 68 |
|
| /* The non-multithreaded case: return just the usual offsets */ |
| 69 |
134138 |
| *dims = broadcast->dims; |
| 70 |
134138 |
| *inds = broadcast->inds; |
| 71 |
134138 |
| return broadcast->offs; |
| 72 |
|
| } |
| 73 |
|
| |
| 74 |
38041 |
| void pdl_freebroadcaststruct(pdl_broadcast *broadcast) { |
| 75 |
38041 |
▶ | PDLDEBUG_f(printf("freebroadcaststruct(%p)\n", broadcast)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(printf("freebroadcaststruct(%p)\n", broadcast)); |
0 |
38041 |
38041 |
|
| 76 |
38041 |
▶ | if (!broadcast->inds) {return;} |
Branch: 1 branch
| Branch | True | False | Total |
| if (!broadcast->inds) {return;} |
12 |
38029 |
38041 |
|
| 77 |
38029 |
| Safefree(broadcast->inds); |
| 78 |
38029 |
| Safefree(broadcast->dims); |
| 79 |
38029 |
| Safefree(broadcast->offs); |
| 80 |
38029 |
| Safefree(broadcast->incs); |
| 81 |
38029 |
| Safefree(broadcast->flags); |
| 82 |
38029 |
| Safefree(broadcast->pdls); |
| 83 |
38029 |
| pdl_clearbroadcaststruct(broadcast); |
| 84 |
|
| } |
| 85 |
|
| |
| 86 |
38029 |
| void pdl_clearbroadcaststruct(pdl_broadcast *it) { |
| 87 |
38029 |
▶ | PDLDEBUG_f(printf("clearbroadcaststruct(%p)\n", it)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(printf("clearbroadcaststruct(%p)\n", it)); |
0 |
38029 |
38029 |
|
| 88 |
38029 |
| it->transvtable=0; it->pdls=0; it->flags = 0; |
| 89 |
38029 |
| it->ndims = it->nimpl = it->npdls = 0; |
| 90 |
38029 |
| it->offs = it->incs = it->realdims = it->inds = it->dims = 0; |
| 91 |
38029 |
| it->gflags=0; /* unsets PDL_BROADCAST_INITIALIZED among others */ |
| 92 |
38029 |
| PDL_CLRMAGIC(it); |
| 93 |
38029 |
| } |
| 94 |
|
| |
| 95 |
112 |
| pdl_error pdl_find_max_pthread( |
| 96 |
|
| pdl **pdls, int npdls, PDL_Indx* realdims, PDL_Indx* creating, |
| 97 |
|
| int target_pthread, |
| 98 |
|
| int *p_maxPthread, /* Maximum achievable pthread */ |
| 99 |
|
| int *p_maxPthreadDim, /* Threaded dim number that has the max num pthreads */ |
| 100 |
|
| int *p_maxPthreadPDL /* PDL that has the max (or right at the target) num pthreads */ |
| 101 |
112 |
| ) { |
| 102 |
112 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 103 |
|
| PDL_Indx j, k, t; |
| 104 |
|
| /* Build int arrays of broadcasted dim numbers and sizes for each pdl */ |
| 105 |
112 |
| PDL_Indx max_remainder = 0; |
| 106 |
112 |
| PDL_Indx nbroadcastedDims[npdls]; |
| 107 |
112 |
| PDL_Indx *broadcastedDims[npdls]; |
| 108 |
112 |
| PDL_Indx *broadcastedDimSizes[npdls]; |
| 109 |
422 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
310 |
112 |
422 |
|
| 110 |
310 |
▶ | if (creating[j]) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; |
55 |
255 |
310 |
|
| 111 |
255 |
| broadcastedDims[j] = (PDL_Indx*) malloc(sizeof(PDL_Indx) * pdls[j]->ndims); |
| 112 |
255 |
▶ | if (!broadcastedDims[j]) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!broadcastedDims[j]) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
0 |
255 |
255 |
|
| 113 |
255 |
| broadcastedDimSizes[j] = (PDL_Indx*) malloc(sizeof(PDL_Indx) * pdls[j]->ndims); |
| 114 |
255 |
▶ | if (!broadcastedDimSizes[j]) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!broadcastedDimSizes[j]) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
0 |
255 |
255 |
|
| 115 |
|
| } |
| 116 |
422 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
310 |
112 |
422 |
|
| 117 |
310 |
▶ | if (creating[j]) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; |
55 |
255 |
310 |
|
| 118 |
534 |
▶ | for ( k=0, t = realdims[j]; t < pdls[j]->ndims; t++, k++ ){ |
Branch: 1 branch
| Branch | True | False | Total |
| for ( k=0, t = realdims[j]; t < pdls[j]->ndims; t++, k++ ){ |
279 |
255 |
534 |
|
| 119 |
279 |
| broadcastedDimSizes[j][k] = pdls[j]->dims[t]; |
| 120 |
279 |
| broadcastedDims[j][k] = t; |
| 121 |
|
| } |
| 122 |
255 |
| nbroadcastedDims[j] = pdls[j]->ndims - realdims[j]; |
| 123 |
|
| } |
| 124 |
|
| /* Go through each broadcasted dim and find best match */ |
| 125 |
112 |
| *p_maxPthread = 0; |
| 126 |
247 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
193 |
54 |
247 |
|
| 127 |
193 |
▶ | if (creating[j]) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; |
47 |
146 |
193 |
|
| 128 |
215 |
▶ | for ( k=0; k < nbroadcastedDims[j]; k++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for ( k=0; k < nbroadcastedDims[j]; k++){ |
102 |
113 |
215 |
|
| 129 |
102 |
| PDL_Indx this_dim = broadcastedDimSizes[j][k]; |
| 130 |
102 |
| PDL_Indx this_remainder = this_dim % target_pthread; |
| 131 |
102 |
▶ | if ( this_remainder == 0 ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if ( this_remainder == 0 ){ |
33 |
69 |
102 |
|
| 132 |
33 |
| *p_maxPthread = target_pthread; |
| 133 |
33 |
| *p_maxPthreadPDL = j; |
| 134 |
33 |
| *p_maxPthreadDim = broadcastedDims[j][k]; |
| 135 |
33 |
| break; |
| 136 |
|
| } |
| 137 |
69 |
▶ | if ( this_dim > *p_maxPthread && this_remainder > max_remainder ){ |
Branch: 2 branches
| Branch | True | False | Total |
| if ( this_dim > *p_maxPthread && this_remainder > max_remainder ){ |
58 |
11 |
69 |
| if ( this_dim > *p_maxPthread && this_remainder > max_remainder ){ |
57 |
1 |
58 |
|
| 138 |
57 |
| max_remainder = this_remainder; |
| 139 |
57 |
| *p_maxPthread = PDLMIN(target_pthread, this_dim); |
| 140 |
57 |
| *p_maxPthreadPDL = j; |
| 141 |
57 |
| *p_maxPthreadDim = broadcastedDims[j][k]; |
| 142 |
|
| } |
| 143 |
|
| } |
| 144 |
|
| /* Don't go any further if target pthread achieved */ |
| 145 |
146 |
▶ | if ( *p_maxPthread == target_pthread ) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if ( *p_maxPthread == target_pthread ) break; |
58 |
88 |
146 |
|
| 146 |
|
| } |
| 147 |
112 |
▶ | PDLDEBUG_f(pdl_dump_broadcasting_info( |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(pdl_dump_broadcasting_info( |
0 |
112 |
112 |
|
| 148 |
|
| npdls, creating, target_pthread, |
| 149 |
|
| nbroadcastedDims, broadcastedDims, broadcastedDimSizes, |
| 150 |
|
| *p_maxPthreadPDL, *p_maxPthreadDim, *p_maxPthread |
| 151 |
|
| )); |
| 152 |
|
| /* Free the stuff we allocated */ |
| 153 |
422 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
310 |
112 |
422 |
|
| 154 |
310 |
▶ | if (creating[j]) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; |
55 |
255 |
310 |
|
| 155 |
255 |
| free(broadcastedDims[j]); |
| 156 |
255 |
| free(broadcastedDimSizes[j]); |
| 157 |
|
| } |
| 158 |
112 |
| return PDL_err; |
| 159 |
|
| } |
| 160 |
|
| |
| 161 |
|
| /* Function to auto-add pthreading magic (i.e. hints for multiple |
| 162 |
|
| processor threads) to the pdls, based on the target number of |
| 163 |
|
| pthreads and the pdl-threaded dimensions. |
| 164 |
|
| noPthreadFlag is a flag indicating that the pdl thread that |
| 165 |
|
| called this function is not multiple processor threading safe, |
| 166 |
|
| so no pthreading magic will be added. |
| 167 |
|
| */ |
| 168 |
44518 |
| pdl_error pdl_autopthreadmagic( pdl **pdls, int npdls, PDL_Indx* realdims, PDL_Indx* creating, int noPthreadFlag ){ |
| 169 |
44518 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 170 |
|
| PDL_Indx j; |
| 171 |
44518 |
| int maxPthreadPDL = -1; /* PDL that has the max (or right at the target) num pthreads */ |
| 172 |
44518 |
| int maxPthreadDim = -1; /* Threaded dim number that has the max num pthreads */ |
| 173 |
44518 |
| int maxPthread = 0; /* Maximum achievable pthread */ |
| 174 |
44518 |
| int target_pthread = pdl_autopthread_targ; |
| 175 |
44518 |
| pdl_autopthread_actual = 0; /* Initialize the global variable indicating actual number of pthreads */ |
| 176 |
44518 |
| pdl_autopthread_dim = -1; /* Initialize the global variable indicating actual dim pthreaded on */ |
| 177 |
|
| |
| 178 |
|
| /* Don't do anything if auto_pthreading is turned off (i.e. equal zero) */ |
| 179 |
44518 |
▶ | if ( !target_pthread ) return PDL_err; |
Branch: 1 branch
| Branch | True | False | Total |
| if ( !target_pthread ) return PDL_err; |
220 |
44298 |
44518 |
|
| 180 |
|
| |
| 181 |
44298 |
| PDL_Indx largest_nvals = 0; |
| 182 |
|
| /* Remove any existing threading magic */ |
| 183 |
152766 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
108468 |
44298 |
152766 |
|
| 184 |
108468 |
▶ | if (creating[j]) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; |
31128 |
77340 |
108468 |
|
| 185 |
77340 |
▶ | MAX2(largest_nvals, pdls[j]->nvals); /* Find largest size */ |
Branch: 1 branch
| Branch | True | False | Total |
| MAX2(largest_nvals, pdls[j]->nvals); /* Find largest size */ |
45600 |
31740 |
77340 |
|
| 186 |
|
| /* Remove thread magic, if there is some set for this pdl */ |
| 187 |
77362 |
| if (pdls[j]->magic && |
| 188 |
22 |
| (pdl_magic_thread_nthreads(pdls[j], NULL))) |
| 189 |
22 |
▶ | PDL_RETERROR(PDL_err, pdl_add_threading_magic(pdls[j], -1, -1)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_add_threading_magic(pdls[j], -1, -1)); |
0 |
22 |
22 |
|
| 190 |
|
| } |
| 191 |
|
| |
| 192 |
44298 |
▶ | if ( noPthreadFlag ) return PDL_err; /* Don't go further if the current pdl function isn't thread-safe */ |
Branch: 1 branch
| Branch | True | False | Total |
| if ( noPthreadFlag ) return PDL_err; /* Don't go further if the current pdl function isn't thread-safe */ |
54 |
44244 |
44298 |
|
| 193 |
|
| /* Don't do anything if we are lower than the threshold */ |
| 194 |
44244 |
▶ | if ( (largest_nvals>>20 /* as MBytes */) < pdl_autopthread_size ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (largest_nvals>>20 /* as MBytes */) < pdl_autopthread_size ) |
44132 |
112 |
44244 |
|
| 195 |
44132 |
| return PDL_err; |
| 196 |
|
| |
| 197 |
112 |
▶ | PDL_RETERROR(PDL_err, pdl_find_max_pthread( |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_find_max_pthread( |
0 |
112 |
112 |
|
| 198 |
|
| pdls, npdls, realdims, creating, target_pthread, |
| 199 |
|
| &maxPthread, &maxPthreadDim, &maxPthreadPDL |
| 200 |
|
| )); |
| 201 |
|
| |
| 202 |
|
| /* Add threading magic */ |
| 203 |
112 |
▶ | if ( maxPthread > 1 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( maxPthread > 1 ) { |
64 |
48 |
112 |
|
| 204 |
64 |
▶ | PDL_RETERROR(PDL_err, pdl_add_threading_magic(pdls[maxPthreadPDL], maxPthreadDim, maxPthread)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_add_threading_magic(pdls[maxPthreadPDL], maxPthreadDim, maxPthread)); |
0 |
64 |
64 |
|
| 205 |
64 |
| pdl_autopthread_actual = maxPthread; /* Set the global variable indicating actual number of pthreads */ |
| 206 |
64 |
| pdl_autopthread_dim = maxPthreadDim; |
| 207 |
|
| } |
| 208 |
112 |
| return PDL_err; |
| 209 |
|
| } |
| 210 |
|
| |
| 211 |
98499 |
| pdl_error pdl_dim_checks( |
| 212 |
|
| pdl_transvtable *vtable, pdl **pdls, |
| 213 |
|
| pdl_broadcast *broadcast, PDL_Indx nimpl, PDL_Indx *creating, |
| 214 |
|
| PDL_Indx *ind_sizes, char load_only |
| 215 |
|
| ) { |
| 216 |
98499 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 217 |
|
| PDL_Indx i, j; |
| 218 |
98499 |
▶ | PDLDEBUG_f(printf("pdl_dim_checks(load_only=%d) %p:\n", load_only, ind_sizes); |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(printf("pdl_dim_checks(load_only=%d) %p:\n", load_only, ind_sizes); |
0 |
98499 |
98499 |
|
| 219 |
|
| printf(" ind_sizes: "); pdl_print_iarr(ind_sizes, vtable->ninds);printf("\n")); |
| 220 |
310384 |
▶ | for (i=0; i<vtable->npdls; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i<vtable->npdls; i++) { |
211902 |
98482 |
310384 |
|
| 221 |
211902 |
| pdl *pdl = pdls[i]; |
| 222 |
211902 |
| PDL_Indx ninds = vtable->par_realdims[i], ndims = pdl->ndims; |
| 223 |
211902 |
▶ | PDLDEBUG_f(printf("pdl_dim_checks pdl %"IND_FLAG" (creating=%"IND_FLAG" ninds=%"IND_FLAG"): ", i, creating[i], ninds)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(printf("pdl_dim_checks pdl %"IND_FLAG" (creating=%"IND_FLAG" ninds=%"IND_FLAG"): ", i, creating[i], ninds)); |
0 |
211902 |
211902 |
|
| 224 |
211902 |
▶ | PDLDEBUG_f(pdl_dump(pdl)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(pdl_dump(pdl)); |
0 |
211902 |
211902 |
|
| 225 |
211902 |
| short flags = vtable->par_flags[i]; |
| 226 |
211902 |
▶ | if (!load_only && creating[i]) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!load_only && creating[i]) continue; |
108928 |
102974 |
211902 |
| if (!load_only && creating[i]) continue; |
31236 |
77692 |
108928 |
|
| 227 |
180666 |
| PDL_Indx *dims = pdl->dims; |
| 228 |
180666 |
| char isoutput = (i >= vtable->nparents); |
| 229 |
218766 |
▶ | for (j=0; j<ninds; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<ninds; j++) { |
38117 |
180649 |
218766 |
|
| 230 |
38117 |
| PDL_Indx ind_id = PDL_IND_ID(vtable, i, j), ind_sz = ind_sizes[ind_id]; |
| 231 |
38117 |
▶ | if (j >= ndims && ind_sz == -1) |
Branch: 2 branches
| Branch | True | False | Total |
| if (j >= ndims && ind_sz == -1) |
11927 |
26190 |
38117 |
| if (j >= ndims && ind_sz == -1) |
6012 |
5915 |
11927 |
|
| 232 |
|
| /* Dimensional promotion when number of dims is less than required: */ |
| 233 |
6012 |
| ind_sz = ind_sizes[ind_id] = 1; |
| 234 |
38117 |
▶ | if (load_only && creating[i]) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (load_only && creating[i]) continue; |
2248 |
35869 |
38117 |
| if (load_only && creating[i]) continue; |
1071 |
1177 |
2248 |
|
| 235 |
37046 |
▶ | if (ind_sz == -1 || (!(flags & PDL_PARAM_ISPHYS) && j < ndims && ind_sz == 1)) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (ind_sz == -1 || (!(flags & PDL_PARAM_ISPHYS) && j < ndims && ind_sz == 1)) { |
20722 |
16324 |
37046 |
| if (ind_sz == -1 || (!(flags & PDL_PARAM_ISPHYS) && j < ndims && ind_sz == 1)) { |
20483 |
239 |
20722 |
| if (ind_sz == -1 || (!(flags & PDL_PARAM_ISPHYS) && j < ndims && ind_sz == 1)) { |
8830 |
11653 |
20483 |
| if (ind_sz == -1 || (!(flags & PDL_PARAM_ISPHYS) && j < ndims && ind_sz == 1)) { |
94 |
8736 |
8830 |
|
| 236 |
16418 |
| ind_sizes[ind_id] = dims[j]; |
| 237 |
16418 |
| continue; |
| 238 |
|
| } |
| 239 |
20628 |
▶ | if (j >= ndims && isoutput && ind_sz != 1) |
Branch: 3 branches
| Branch | True | False | Total |
| if (j >= ndims && isoutput && ind_sz != 1) |
11666 |
8962 |
20628 |
| if (j >= ndims && isoutput && ind_sz != 1) |
7 |
11659 |
11666 |
| if (j >= ndims && isoutput && ind_sz != 1) |
5 |
2 |
7 |
|
| 240 |
5 |
| return pdl_param_error(vtable,i, |
| 241 |
|
| pdls, nimpl, creating, |
| 242 |
|
| "index '%s' size %"IND_FLAG", can't broadcast over output ndarray with size > 1", |
| 243 |
5 |
| vtable->ind_names[ind_id], ind_sz |
| 244 |
|
| ); |
| 245 |
20623 |
▶ | if (isoutput && ind_sz != 1 && pdl->vafftrans && pdl->vafftrans->incs[j] == 0) |
Branch: 4 branches
| Branch | True | False | Total |
| if (isoutput && ind_sz != 1 && pdl->vafftrans && pdl->vafftrans->incs[j] == 0) |
959 |
19664 |
20623 |
| if (isoutput && ind_sz != 1 && pdl->vafftrans && pdl->vafftrans->incs[j] == 0) |
942 |
17 |
959 |
| if (isoutput && ind_sz != 1 && pdl->vafftrans && pdl->vafftrans->incs[j] == 0) |
336 |
606 |
942 |
| if (isoutput && ind_sz != 1 && pdl->vafftrans && pdl->vafftrans->incs[j] == 0) |
2 |
334 |
336 |
|
| 246 |
2 |
| return pdl_param_error(vtable,i, |
| 247 |
|
| pdls, nimpl, creating, |
| 248 |
|
| "index '%s' size %"IND_FLAG", can't broadcast over dummy dim with size > 1", |
| 249 |
2 |
| vtable->ind_names[ind_id], ind_sz |
| 250 |
|
| ); |
| 251 |
20621 |
▶ | if (j < ndims && ind_sz != dims[j] && (isoutput || dims[j] != 1)) |
Branch: 4 branches
| Branch | True | False | Total |
| if (j < ndims && ind_sz != dims[j] && (isoutput || dims[j] != 1)) |
8960 |
11661 |
20621 |
| if (j < ndims && ind_sz != dims[j] && (isoutput || dims[j] != 1)) |
12 |
8948 |
8960 |
| if (j < ndims && ind_sz != dims[j] && (isoutput || dims[j] != 1)) |
4 |
8 |
12 |
| if (j < ndims && ind_sz != dims[j] && (isoutput || dims[j] != 1)) |
0 |
4 |
4 |
|
| 252 |
8 |
| return pdl_param_error(vtable,i, |
| 253 |
|
| pdls, nimpl, creating, |
| 254 |
|
| "index '%s' size %"IND_FLAG", but ndarray dim has size %"IND_FLAG, |
| 255 |
8 |
| vtable->ind_names[ind_id], ind_sz, dims[j] |
| 256 |
|
| ); |
| 257 |
20613 |
▶ | if (j < ndims && ind_sz != dims[j] && |
Branch: 3 branches
| Branch | True | False | Total |
| if (j < ndims && ind_sz != dims[j] && |
8952 |
11661 |
20613 |
| if (j < ndims && ind_sz != dims[j] && |
4 |
8948 |
8952 |
| if (j < ndims && ind_sz != dims[j] && |
2 |
2 |
4 |
|
| 258 |
2 |
▶ | !load_only && !creating[i] && |
Branch: 2 branches
| Branch | True | False | Total |
| !load_only && !creating[i] && |
2 |
0 |
2 |
| !load_only && !creating[i] && |
2 |
0 |
2 |
|
| 259 |
2 |
| ind_sz > 1 && |
| 260 |
2 |
▶ | (flags & PDL_PARAM_ISPHYS) |
Branch: 1 branch
| Branch | True | False | Total |
| (flags & PDL_PARAM_ISPHYS) |
2 |
0 |
2 |
|
| 261 |
|
| ) |
| 262 |
2 |
| return pdl_param_error(vtable,i, |
| 263 |
|
| pdls, nimpl, creating, |
| 264 |
|
| "index '%s' size %"IND_FLAG", but ndarray dim has size %"IND_FLAG, |
| 265 |
2 |
| vtable->ind_names[ind_id], ind_sz, dims[j] |
| 266 |
|
| ); |
| 267 |
|
| } |
| 268 |
|
| } |
| 269 |
98482 |
▶ | PDLDEBUG_f(printf("pdl_dim_checks after:\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(printf("pdl_dim_checks after:\n"); |
0 |
98482 |
98482 |
|
| 270 |
|
| printf(" ind_sizes: "); pdl_print_iarr(ind_sizes, vtable->ninds); |
| 271 |
|
| printf("\n")); |
| 272 |
98482 |
| return PDL_err; |
| 273 |
|
| } |
| 274 |
|
| |
| 275 |
44518 |
| static pdl_error pdl_broadcast_dim_checks( |
| 276 |
|
| pdl_transvtable *vtable, pdl **pdls, |
| 277 |
|
| pdl_broadcast *broadcast, PDL_Indx *creating, |
| 278 |
|
| PDL_Indx nimpl, PDL_Indx *realdims, PDL_Indx npdls, PDL_Indx *nthp |
| 279 |
|
| ) { |
| 280 |
44518 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 281 |
|
| PDL_Indx j, nth /* Index to dimensions */; |
| 282 |
72870 |
▶ | for (nth=0; nth<nimpl; nth++) { // Loop over number of implicit broadcast dims |
Branch: 1 branch
| Branch | True | False | Total |
| for (nth=0; nth<nimpl; nth++) { // Loop over number of implicit broadcast dims |
28365 |
44505 |
72870 |
|
| 283 |
92088 |
▶ | for (j=0; j<npdls; j++) { // Now loop over the PDLs to be merged |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { // Now loop over the PDLs to be merged |
63736 |
28352 |
92088 |
|
| 284 |
63736 |
▶ | if (creating[j]) continue; // If jth PDL is null, don't bother trying to match |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; // If jth PDL is null, don't bother trying to match |
13728 |
50008 |
63736 |
|
| 285 |
50008 |
▶ | char isoutput = (vtable && j >= vtable->nparents); |
Branch: 2 branches
| Branch | True | False | Total |
| char isoutput = (vtable && j >= vtable->nparents); |
49977 |
31 |
50008 |
| char isoutput = (vtable && j >= vtable->nparents); |
14841 |
35136 |
49977 |
|
| 286 |
50008 |
▶ | if (nth >= pdls[j]->broadcastids[0]-realdims[j]) { /* off end of current PDL's dimlist */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (nth >= pdls[j]->broadcastids[0]-realdims[j]) { /* off end of current PDL's dimlist */ |
11032 |
38976 |
50008 |
|
| 287 |
11032 |
▶ | if (isoutput && broadcast->dims[nth] != 1) |
Branch: 2 branches
| Branch | True | False | Total |
| if (isoutput && broadcast->dims[nth] != 1) |
20 |
11012 |
11032 |
| if (isoutput && broadcast->dims[nth] != 1) |
5 |
15 |
20 |
|
| 288 |
5 |
| return pdl_param_error(vtable,nth, |
| 289 |
|
| pdls, nimpl, creating, |
| 290 |
|
| "implicit dim %"IND_FLAG" size %"IND_FLAG", can't broadcast over output ndarray with size > 1", |
| 291 |
5 |
| nth, broadcast->dims[nth] |
| 292 |
|
| ); |
| 293 |
11027 |
| continue; |
| 294 |
|
| } |
| 295 |
38976 |
| PDL_Indx cur_pdl_dim = pdls[j]->dims[nth+realdims[j]]; |
| 296 |
38976 |
▶ | if (isoutput && cur_pdl_dim == 1 && cur_pdl_dim != broadcast->dims[nth]) |
Branch: 3 branches
| Branch | True | False | Total |
| if (isoutput && cur_pdl_dim == 1 && cur_pdl_dim != broadcast->dims[nth]) |
14821 |
24155 |
38976 |
| if (isoutput && cur_pdl_dim == 1 && cur_pdl_dim != broadcast->dims[nth]) |
4496 |
10325 |
14821 |
| if (isoutput && cur_pdl_dim == 1 && cur_pdl_dim != broadcast->dims[nth]) |
5 |
4491 |
4496 |
|
| 297 |
5 |
| return pdl_param_error(vtable,nth, |
| 298 |
|
| pdls, nimpl, creating, |
| 299 |
|
| "implicit dim %"IND_FLAG" size %"IND_FLAG", but dim has size %"IND_FLAG, |
| 300 |
5 |
| nth, broadcast->dims[nth], cur_pdl_dim |
| 301 |
|
| ); |
| 302 |
38971 |
▶ | if (isoutput && cur_pdl_dim != 1 && pdls[j]->vafftrans && pdls[j]->vafftrans->incs[nth+realdims[j]] == 0) |
Branch: 4 branches
| Branch | True | False | Total |
| if (isoutput && cur_pdl_dim != 1 && pdls[j]->vafftrans && pdls[j]->vafftrans->incs[nth+realdims[j]] == 0) |
14816 |
24155 |
38971 |
| if (isoutput && cur_pdl_dim != 1 && pdls[j]->vafftrans && pdls[j]->vafftrans->incs[nth+realdims[j]] == 0) |
10325 |
4491 |
14816 |
| if (isoutput && cur_pdl_dim != 1 && pdls[j]->vafftrans && pdls[j]->vafftrans->incs[nth+realdims[j]] == 0) |
1736 |
8589 |
10325 |
| if (isoutput && cur_pdl_dim != 1 && pdls[j]->vafftrans && pdls[j]->vafftrans->incs[nth+realdims[j]] == 0) |
2 |
1734 |
1736 |
|
| 303 |
2 |
| return pdl_param_error(vtable,nth, |
| 304 |
|
| pdls, nimpl, creating, |
| 305 |
|
| "implicit dim %"IND_FLAG" size %"IND_FLAG", but dim is dummy", |
| 306 |
2 |
| nth, broadcast->dims[nth] |
| 307 |
|
| ); |
| 308 |
38969 |
▶ | if (cur_pdl_dim != 1) { // If the current dim in the current PDL is not 1, |
Branch: 1 branch
| Branch | True | False | Total |
| if (cur_pdl_dim != 1) { // If the current dim in the current PDL is not 1, |
31874 |
7095 |
38969 |
|
| 309 |
31874 |
▶ | if (broadcast->dims[nth] != 1) { // ... and the current planned size isn't 1, |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->dims[nth] != 1) { // ... and the current planned size isn't 1, |
9062 |
22812 |
31874 |
|
| 310 |
9062 |
▶ | if (broadcast->dims[nth] != cur_pdl_dim) // ... then check to make sure they're the same. |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->dims[nth] != cur_pdl_dim) // ... then check to make sure they're the same. |
1 |
9061 |
9062 |
|
| 311 |
1 |
| return pdl_param_error(vtable,j, |
| 312 |
|
| pdls, nimpl, creating, |
| 313 |
|
| "Mismatched implicit broadcast dimension %"IND_FLAG": size %"IND_FLAG" vs. %"IND_FLAG, |
| 314 |
1 |
| nth,broadcast->dims[nth],pdls[j]->dims[nth+realdims[j]] |
| 315 |
|
| ); |
| 316 |
|
| /* If we're still here, they're the same -- OK! */ |
| 317 |
|
| } else { // current planned size is 1 -- mod it to match this PDL |
| 318 |
22812 |
| broadcast->dims[nth] = cur_pdl_dim; |
| 319 |
|
| } |
| 320 |
31873 |
| PDL_BRC_INC(broadcast->incs, npdls, j, nth) = // Update the corresponding data stride |
| 321 |
31873 |
▶ | PDL_REPRINC(pdls[j],nth+realdims[j]);// from the PDL or from its vafftrans if relevant. |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_REPRINC(pdls[j],nth+realdims[j]);// from the PDL or from its vafftrans if relevant. |
6288 |
25585 |
31873 |
|
| 322 |
|
| } |
| 323 |
|
| } |
| 324 |
|
| } |
| 325 |
44505 |
| *nthp = nth; |
| 326 |
44505 |
| return PDL_err; |
| 327 |
|
| } |
| 328 |
|
| |
| 329 |
|
| /* The assumptions this function makes: |
| 330 |
|
| * pdls is dynamic and may go away -> copied |
| 331 |
|
| * realdims is static and is NOT copied and NOT freed!!! |
| 332 |
|
| * creating is only used inside this routine. |
| 333 |
|
| * vtable is assumed static. |
| 334 |
|
| * |
| 335 |
|
| * Only the first thread-magicked pdl is taken into account. |
| 336 |
|
| * |
| 337 |
|
| * noPthreadFlag is a flag to indicate the trans is not pthreading safe |
| 338 |
|
| * (i.e. don't attempt to create multiple posix threads to execute) |
| 339 |
|
| */ |
| 340 |
44518 |
| pdl_error pdl_initbroadcaststruct(int nobl, |
| 341 |
|
| pdl **pdls,PDL_Indx *realdims,PDL_Indx *creating,PDL_Indx npdls, |
| 342 |
|
| pdl_transvtable *vtable,pdl_broadcast *broadcast, |
| 343 |
|
| PDL_Indx *ind_sizes_UNUSED /*CORE21*/, PDL_Indx *inc_sizes_UNUSED, |
| 344 |
|
| char *flags_UNUSED /*CORE21*/, int noPthreadFlag |
| 345 |
44518 |
| ) { |
| 346 |
44518 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 347 |
44518 |
▶ | PDLDEBUG_f(printf("initbroadcaststruct(%p)\n", broadcast)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(printf("initbroadcaststruct(%p)\n", broadcast)); |
0 |
44518 |
44518 |
|
| 348 |
51007 |
▶ | char already_alloced = (broadcast->magicno == PDL_BRC_MAGICNO && |
Branch: 1 branch
| Branch | True | False | Total |
| char already_alloced = (broadcast->magicno == PDL_BRC_MAGICNO && |
6489 |
38029 |
44518 |
|
| 349 |
6489 |
▶ | broadcast->gflags & PDL_BROADCAST_INITIALIZED); |
Branch: 1 branch
| Branch | True | False | Total |
| broadcast->gflags & PDL_BROADCAST_INITIALIZED); |
6489 |
0 |
6489 |
|
| 350 |
44518 |
▶ | PDL_Indx already_nthr = already_alloced ? broadcast->mag_nthr : -1; |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_Indx already_nthr = already_alloced ? broadcast->mag_nthr : -1; |
6489 |
38029 |
44518 |
|
| 351 |
44518 |
▶ | PDL_Indx already_ndims = already_alloced ? broadcast->ndims : -1; |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_Indx already_ndims = already_alloced ? broadcast->ndims : -1; |
6489 |
38029 |
44518 |
|
| 352 |
44518 |
| PDL_BRC_SETMAGIC(broadcast); |
| 353 |
44518 |
| broadcast->gflags = 0; |
| 354 |
44518 |
| broadcast->npdls = npdls; |
| 355 |
44518 |
| broadcast->realdims = realdims; |
| 356 |
44518 |
| broadcast->transvtable = vtable; |
| 357 |
44518 |
| broadcast->mag_nth = -1; |
| 358 |
44518 |
| broadcast->mag_nthpdl = -1; |
| 359 |
44518 |
| broadcast->mag_nthr = -1; |
| 360 |
44518 |
| broadcast->mag_skip = 0; |
| 361 |
44518 |
| broadcast->mag_stride = 0; |
| 362 |
|
| |
| 363 |
|
| /* Accumulate the maximum number of broadcast dims across the collection of PDLs */ |
| 364 |
44518 |
| PDL_Indx nids = 0, nimpl=0, i, j; |
| 365 |
153524 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
109006 |
44518 |
153524 |
|
| 366 |
109006 |
▶ | if (creating[j]) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; |
31248 |
77758 |
109006 |
|
| 367 |
77758 |
▶ | MAX2(nids,pdls[j]->nbroadcastids); |
Branch: 1 branch
| Branch | True | False | Total |
| MAX2(nids,pdls[j]->nbroadcastids); |
44509 |
33249 |
77758 |
|
| 368 |
77758 |
▶ | MAX2(nimpl,pdls[j]->broadcastids[0] - realdims[j]); |
Branch: 1 branch
| Branch | True | False | Total |
| MAX2(nimpl,pdls[j]->broadcastids[0] - realdims[j]); |
22332 |
55426 |
77758 |
|
| 369 |
|
| } |
| 370 |
44518 |
| PDL_Indx ndims = broadcast->nimpl = nimpl; |
| 371 |
|
| |
| 372 |
44518 |
▶ | PDL_RETERROR(PDL_err, pdl_autopthreadmagic(pdls, npdls, realdims, creating, noPthreadFlag)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_autopthreadmagic(pdls, npdls, realdims, creating, noPthreadFlag)); |
0 |
44518 |
44518 |
|
| 373 |
|
| |
| 374 |
44518 |
| PDL_Indx nbroadcastids[nids], nthr = 0, nthrd; |
| 375 |
153524 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
109006 |
44518 |
153524 |
|
| 376 |
109006 |
▶ | if (creating[j]) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; |
31248 |
77758 |
109006 |
|
| 377 |
|
| /* Check for magical ndarrays (parallelized) */ |
| 378 |
77758 |
▶ | if (!nthr && |
Branch: 1 branch
| Branch | True | False | Total |
| if (!nthr && |
77554 |
204 |
77758 |
|
| 379 |
77554 |
▶ | pdls[j]->magic && |
Branch: 1 branch
| Branch | True | False | Total |
| pdls[j]->magic && |
111 |
77443 |
77554 |
|
| 380 |
111 |
▶ | (nthr = pdl_magic_thread_nthreads(pdls[j],&nthrd)) |
Branch: 1 branch
| Branch | True | False | Total |
| (nthr = pdl_magic_thread_nthreads(pdls[j],&nthrd)) |
111 |
0 |
111 |
|
| 381 |
|
| ) { |
| 382 |
111 |
▶ | if ((broadcast->mag_nth = nthrd - realdims[j]) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((broadcast->mag_nth = nthrd - realdims[j]) < 0) |
0 |
111 |
111 |
|
| 383 |
0 |
| return pdl_param_error(vtable,j, |
| 384 |
|
| pdls, nimpl, creating, |
| 385 |
|
| "Cannot magick non-broadcasted dims"); |
| 386 |
111 |
| broadcast->mag_nthpdl = j; |
| 387 |
111 |
| broadcast->mag_nthr = nthr; |
| 388 |
|
| } |
| 389 |
155522 |
▶ | for (i=0; i<nids; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i<nids; i++) |
77764 |
77758 |
155522 |
|
| 390 |
77764 |
| ndims += nbroadcastids[i] = |
| 391 |
77764 |
▶ | PDLMAX(0, pdls[j]->nbroadcastids > nids ? 0 : |
Branch: 3 branches
| Branch | True | False | Total |
| PDLMAX(0, pdls[j]->nbroadcastids > nids ? 0 : |
77764 |
0 |
77764 |
| PDLMAX(0, pdls[j]->nbroadcastids > nids ? 0 : |
28054 |
49710 |
77764 |
| PDLMAX(0, pdls[j]->nbroadcastids > nids ? 0 : |
28054 |
0 |
28054 |
|
| 392 |
|
| pdls[j]->broadcastids[i+1] - pdls[j]->broadcastids[i]); |
| 393 |
|
| } |
| 394 |
44518 |
▶ | if (nthr) |
Branch: 1 branch
| Branch | True | False | Total |
| if (nthr) |
111 |
44407 |
44518 |
|
| 395 |
111 |
| broadcast->gflags |= PDL_BROADCAST_MAGICKED; |
| 396 |
44518 |
| ndims += broadcast->nextra = PDLMAX(0, nobl - ndims); /* If too few, add enough implicit dims */ |
| 397 |
|
| |
| 398 |
44518 |
| broadcast->ndims = ndims; |
| 399 |
|
| |
| 400 |
44518 |
| PDL_Indx nthr1 = PDLMAX(nthr, 1); |
| 401 |
44518 |
▶ | if (!already_alloced || already_nthr != nthr1 || ndims != already_ndims) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!already_alloced || already_nthr != nthr1 || ndims != already_ndims) { |
6489 |
38029 |
44518 |
| if (!already_alloced || already_nthr != nthr1 || ndims != already_ndims) { |
0 |
6489 |
6489 |
| if (!already_alloced || already_nthr != nthr1 || ndims != already_ndims) { |
0 |
0 |
0 |
|
| 402 |
44518 |
▶ | if (already_alloced) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (already_alloced) { |
6489 |
38029 |
44518 |
|
| 403 |
6489 |
| Safefree(broadcast->inds); |
| 404 |
6489 |
| Safefree(broadcast->dims); |
| 405 |
6489 |
| Safefree(broadcast->offs); |
| 406 |
|
| } |
| 407 |
44518 |
▶ | Newxz(broadcast->inds, ndims * nthr1, PDL_Indx); /* Create space for pthread-specific inds (i.e. copy for each pthread)*/ |
Branch: 1 branch
| Branch | True | False | Total |
| Newxz(broadcast->inds, ndims * nthr1, PDL_Indx); /* Create space for pthread-specific inds (i.e. copy for each pthread)*/ |
0 |
44518 |
44518 |
|
| 408 |
44518 |
▶ | if (broadcast->inds == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->inds in pdlbroadcast.c"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->inds == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->inds in pdlbroadcast.c"); |
0 |
44518 |
44518 |
|
| 409 |
44518 |
▶ | Newxz(broadcast->dims, ndims * nthr1, PDL_Indx); |
Branch: 1 branch
| Branch | True | False | Total |
| Newxz(broadcast->dims, ndims * nthr1, PDL_Indx); |
0 |
44518 |
44518 |
|
| 410 |
44518 |
▶ | if (broadcast->dims == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->dims in pdlbroadcast.c"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->dims == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->dims in pdlbroadcast.c"); |
0 |
44518 |
44518 |
|
| 411 |
44518 |
▶ | Newxz(broadcast->offs, npdls * nthr1, PDL_Indx); /* Create space for pthread-specific offs */ |
Branch: 1 branch
| Branch | True | False | Total |
| Newxz(broadcast->offs, npdls * nthr1, PDL_Indx); /* Create space for pthread-specific offs */ |
0 |
44518 |
44518 |
|
| 412 |
44518 |
▶ | if (broadcast->offs == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->offs in pdlbroadcast.c"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->offs == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->offs in pdlbroadcast.c"); |
0 |
44518 |
44518 |
|
| 413 |
|
| } |
| 414 |
|
| PDL_Indx nth; |
| 415 |
134993 |
▶ | for (nth=0; nth<ndims; nth++) broadcast->dims[nth]=1; // all start size 1 |
Branch: 1 branch
| Branch | True | False | Total |
| for (nth=0; nth<ndims; nth++) broadcast->dims[nth]=1; // all start size 1 |
90475 |
44518 |
134993 |
|
| 416 |
|
| |
| 417 |
44518 |
▶ | if (!already_alloced) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!already_alloced) { |
38029 |
6489 |
44518 |
|
| 418 |
38029 |
| broadcast->pdls = copy_pdl_array(pdls,npdls); |
| 419 |
38029 |
▶ | Newxz(broadcast->incs, ndims * npdls, PDL_Indx); |
Branch: 1 branch
| Branch | True | False | Total |
| Newxz(broadcast->incs, ndims * npdls, PDL_Indx); |
0 |
38029 |
38029 |
|
| 420 |
38029 |
▶ | if (broadcast->incs == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->incs in pdlbroadcast.c"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->incs == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->incs in pdlbroadcast.c"); |
0 |
38029 |
38029 |
|
| 421 |
38029 |
| Newxz(broadcast->flags, npdls, char); |
| 422 |
38029 |
▶ | if (broadcast->flags == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->flags in pdlbroadcast.c"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->flags == NULL) return pdl_make_error_simple(PDL_EFATAL, "Failed to allocate memory for broadcast->flags in pdlbroadcast.c"); |
0 |
38029 |
38029 |
|
| 423 |
|
| } |
| 424 |
|
| |
| 425 |
44518 |
| char *flags = broadcast->flags; /* shortcut for the remainder */ |
| 426 |
153524 |
▶ | for (i=0;i<npdls; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0;i<npdls; i++) |
109006 |
44518 |
153524 |
|
| 427 |
109006 |
▶ | if (vtable && vtable->par_flags[i] & PDL_PARAM_ISTEMP) |
Branch: 2 branches
| Branch | True | False | Total |
| if (vtable && vtable->par_flags[i] & PDL_PARAM_ISTEMP) |
108975 |
31 |
109006 |
| if (vtable && vtable->par_flags[i] & PDL_PARAM_ISTEMP) |
253 |
108722 |
108975 |
|
| 428 |
253 |
| flags[i] |= PDL_BROADCAST_TEMP; |
| 429 |
|
| |
| 430 |
|
| /* check dims, make implicit inds */ |
| 431 |
44518 |
▶ | PDL_RETERROR(PDL_err, pdl_broadcast_dim_checks( |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_broadcast_dim_checks( |
13 |
44505 |
44518 |
|
| 432 |
|
| vtable, pdls, broadcast, creating, nimpl, realdims, npdls, &nth |
| 433 |
|
| )); |
| 434 |
|
| |
| 435 |
|
| /* Go through everything again and make the real things */ |
| 436 |
|
| |
| 437 |
|
| PDL_Indx nthid; |
| 438 |
89003 |
▶ | for (nthid=0; nthid<nids; nthid++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (nthid=0; nthid<nids; nthid++) { |
44498 |
44505 |
89003 |
|
| 439 |
44502 |
▶ | for (i=0; i<nbroadcastids[nthid]; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i<nbroadcastids[nthid]; i++) { |
4 |
44498 |
44502 |
|
| 440 |
12 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
8 |
4 |
12 |
|
| 441 |
8 |
| pdl *pdl = pdls[j]; |
| 442 |
8 |
▶ | if (PDL_BISTEMP(flags[j])) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PDL_BISTEMP(flags[j])) |
0 |
8 |
8 |
|
| 443 |
0 |
| PDL_BRC_INC(broadcast->incs, npdls, j, nth) = |
| 444 |
0 |
| pdl->dimincs[pdl->ndims-1]; |
| 445 |
8 |
▶ | if (creating[j]) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (creating[j]) continue; |
0 |
8 |
8 |
|
| 446 |
8 |
▶ | if (pdl->nbroadcastids < nthid) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (pdl->nbroadcastids < nthid) continue; |
0 |
8 |
8 |
|
| 447 |
8 |
▶ | if (pdl->broadcastids[nthid+1]-pdl->broadcastids[nthid] <= i) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (pdl->broadcastids[nthid+1]-pdl->broadcastids[nthid] <= i) continue; |
0 |
8 |
8 |
|
| 448 |
8 |
| PDL_Indx mywhichdim = i+pdl->broadcastids[nthid], mydim = pdl->dims[mywhichdim]; |
| 449 |
8 |
▶ | if (mydim == 1) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (mydim == 1) continue; |
0 |
8 |
8 |
|
| 450 |
8 |
▶ | if (broadcast->dims[nth] == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->dims[nth] == 1) { |
4 |
4 |
8 |
|
| 451 |
4 |
| broadcast->dims[nth] = mydim; |
| 452 |
|
| } else { |
| 453 |
4 |
▶ | if (broadcast->dims[nth] != mydim) |
Branch: 1 branch
| Branch | True | False | Total |
| if (broadcast->dims[nth] != mydim) |
0 |
4 |
4 |
|
| 454 |
0 |
| return pdl_param_error(vtable,j, |
| 455 |
|
| pdls, nimpl, creating, |
| 456 |
|
| "Mismatched implicit broadcast dimension %"IND_FLAG": should be %"IND_FLAG", is %"IND_FLAG"", |
| 457 |
|
| i, |
| 458 |
0 |
| broadcast->dims[nth], |
| 459 |
0 |
| pdl->dims[i+realdims[j]]); |
| 460 |
|
| } |
| 461 |
8 |
| PDL_BRC_INC(broadcast->incs, npdls, j, nth) = |
| 462 |
8 |
▶ | PDL_REPRINC(pdl,mywhichdim); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_REPRINC(pdl,mywhichdim); |
6 |
2 |
8 |
|
| 463 |
|
| } |
| 464 |
4 |
| nth++; |
| 465 |
|
| } |
| 466 |
|
| } |
| 467 |
|
| |
| 468 |
|
| /* If threading, make the true offsets and dims.. */ |
| 469 |
44505 |
▶ | if (nthr > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (nthr > 0) { |
111 |
44394 |
44505 |
|
| 470 |
111 |
| PDL_Indx mag_dim = broadcast->dims[broadcast->mag_nth], |
| 471 |
111 |
| n1 = mag_dim / nthr, n2 = mag_dim % nthr; |
| 472 |
111 |
| broadcast->mag_stride = n1; |
| 473 |
111 |
▶ | if (n2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n2) { |
46 |
65 |
111 |
|
| 474 |
46 |
| n1++; |
| 475 |
46 |
| broadcast->mag_skip = n2; |
| 476 |
|
| } |
| 477 |
111 |
| broadcast->dims[broadcast->mag_nth] = n1; |
| 478 |
564 |
▶ | for (i=1; i<nthr; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=1; i<nthr; i++) |
453 |
111 |
564 |
|
| 479 |
1454 |
▶ | for (j=0; j<ndims; j++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<ndims; j++) |
1001 |
453 |
1454 |
|
| 480 |
1001 |
| broadcast->dims[j + i*ndims] = broadcast->dims[j]; |
| 481 |
111 |
▶ | if (n2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n2) |
46 |
65 |
111 |
|
| 482 |
354 |
▶ | for (i=n2; i<nthr; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=n2; i<nthr; i++) |
308 |
46 |
354 |
|
| 483 |
308 |
| broadcast->dims[broadcast->mag_nth + i*ndims]--; |
| 484 |
|
| } |
| 485 |
44505 |
| broadcast->gflags |= PDL_BROADCAST_INITIALIZED; |
| 486 |
44505 |
▶ | PDLDEBUG_f(pdl_dump_broadcast(broadcast)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDLDEBUG_f(pdl_dump_broadcast(broadcast)); |
0 |
44505 |
44505 |
|
| 487 |
44505 |
| return PDL_err; |
| 488 |
|
| } |
| 489 |
|
| |
| 490 |
31244 |
| pdl_error pdl_broadcast_create_parameter(pdl_broadcast *broadcast, PDL_Indx j,PDL_Indx *dims, |
| 491 |
|
| int temp) |
| 492 |
|
| { |
| 493 |
31244 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 494 |
|
| PDL_Indx i; |
| 495 |
31244 |
▶ | PDL_Indx td = temp ? 0 : broadcast->nimpl; |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_Indx td = temp ? 0 : broadcast->nimpl; |
30991 |
253 |
31244 |
|
| 496 |
31244 |
▶ | if (!temp && broadcast->nimpl != broadcast->ndims - broadcast->nextra) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!temp && broadcast->nimpl != broadcast->ndims - broadcast->nextra) { |
30991 |
253 |
31244 |
| if (!temp && broadcast->nimpl != broadcast->ndims - broadcast->nextra) { |
0 |
30991 |
30991 |
|
| 497 |
0 |
| return pdl_make_error(PDL_EUSERERROR, |
| 498 |
|
| "%s: trying to create parameter '%s' while explicitly broadcasting.\n" |
| 499 |
|
| "See the manual for why this is impossible", |
| 500 |
0 |
| broadcast->transvtable->name, |
| 501 |
0 |
| broadcast->transvtable->par_names[j] |
| 502 |
|
| ); |
| 503 |
|
| } |
| 504 |
31244 |
▶ | if (!broadcast->pdls[j] && !(broadcast->pdls[j] = pdl_pdlnew())) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!broadcast->pdls[j] && !(broadcast->pdls[j] = pdl_pdlnew())) |
0 |
31244 |
31244 |
| if (!broadcast->pdls[j] && !(broadcast->pdls[j] = pdl_pdlnew())) |
0 |
0 |
0 |
|
| 505 |
0 |
| return pdl_make_error_simple(PDL_EFATAL, "Error in pdlnew"); |
| 506 |
31244 |
▶ | PDL_RETERROR(PDL_err, pdl_reallocdims(broadcast->pdls[j], broadcast->realdims[j] + td + (temp ? 1 : 0))); |
Branch: 2 branches
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_reallocdims(broadcast->pdls[j], broadcast->realdims[j] + td + (temp ? 1 : 0))); |
253 |
30991 |
31244 |
| PDL_RETERROR(PDL_err, pdl_reallocdims(broadcast->pdls[j], broadcast->realdims[j] + td + (temp ? 1 : 0))); |
0 |
31244 |
31244 |
|
| 507 |
45708 |
▶ | for (i=0; i<broadcast->realdims[j] + (temp ? 1 : 0); i++) |
Branch: 2 branches
| Branch | True | False | Total |
| for (i=0; i<broadcast->realdims[j] + (temp ? 1 : 0); i++) |
825 |
44883 |
45708 |
| for (i=0; i<broadcast->realdims[j] + (temp ? 1 : 0); i++) |
14464 |
31244 |
45708 |
|
| 508 |
14464 |
| broadcast->pdls[j]->dims[i] = dims[i]; |
| 509 |
31244 |
▶ | if (!temp) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!temp) |
30991 |
253 |
31244 |
|
| 510 |
44702 |
▶ | for (i=0; i<broadcast->nimpl; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i<broadcast->nimpl; i++) |
13711 |
30991 |
44702 |
|
| 511 |
13711 |
| broadcast->pdls[j]->dims[i+broadcast->realdims[j]] = |
| 512 |
14 |
▶ | (i == broadcast->mag_nth && broadcast->mag_nthr > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| (i == broadcast->mag_nth && broadcast->mag_nthr > 0) |
14 |
0 |
14 |
|
| 513 |
14 |
| ? PDL_BRC_OFFSET(broadcast->mag_nthr, broadcast) |
| 514 |
13725 |
▶ | : broadcast->dims[i]; |
Branch: 1 branch
| Branch | True | False | Total |
| : broadcast->dims[i]; |
14 |
13697 |
13711 |
|
| 515 |
31244 |
| broadcast->pdls[j]->broadcastids[0] = td + broadcast->realdims[j]; |
| 516 |
31244 |
| pdl_resize_defaultincs(broadcast->pdls[j]); |
| 517 |
44970 |
▶ | for (i=0; i<broadcast->nimpl; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i<broadcast->nimpl; i++) { |
13726 |
31244 |
44970 |
|
| 518 |
13726 |
| PDL_BRC_INC(broadcast->incs, broadcast->npdls, j, i) = |
| 519 |
13726 |
▶ | temp ? 0 : |
Branch: 1 branch
| Branch | True | False | Total |
| temp ? 0 : |
13711 |
15 |
13726 |
|
| 520 |
13711 |
▶ | PDL_REPRINC(broadcast->pdls[j],i+broadcast->realdims[j]); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_REPRINC(broadcast->pdls[j],i+broadcast->realdims[j]); |
0 |
13711 |
13711 |
|
| 521 |
|
| } |
| 522 |
31244 |
| return PDL_err; |
| 523 |
|
| } |
| 524 |
|
| |
| 525 |
44147 |
| int pdl_startbroadcastloop(pdl_broadcast *broadcast,pdl_error (*func)(pdl_trans *), |
| 526 |
|
| pdl_trans *t, pdl_error *error_ret) { |
| 527 |
44147 |
| PDL_Indx j, npdls = broadcast->npdls; |
| 528 |
44147 |
▶ | if ((broadcast->gflags & (PDL_BROADCAST_MAGICKED | PDL_BROADCAST_MAGICK_BUSY)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((broadcast->gflags & (PDL_BROADCAST_MAGICKED | PDL_BROADCAST_MAGICK_BUSY)) |
115 |
44032 |
44147 |
|
| 529 |
|
| == PDL_BROADCAST_MAGICKED ) { |
| 530 |
|
| /* If no function supplied (i.e. being called from PDL::broadcast_over), don't run in parallel */ |
| 531 |
115 |
▶ | if (!func) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!func) |
0 |
115 |
115 |
|
| 532 |
0 |
| broadcast->gflags &= ~PDL_BROADCAST_MAGICKED; /* Cancel thread_magicked */ |
| 533 |
|
| else { |
| 534 |
115 |
| broadcast->gflags |= PDL_BROADCAST_MAGICK_BUSY; |
| 535 |
|
| /* Do the broadcastloop magically (i.e. in parallel) */ |
| 536 |
459 |
▶ | for (j=0; j<npdls; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) { |
344 |
115 |
459 |
|
| 537 |
344 |
▶ | if (!(t->vtable->par_flags[j] & PDL_PARAM_ISTEMP)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(t->vtable->par_flags[j] & PDL_PARAM_ISTEMP)) continue; |
344 |
0 |
344 |
|
| 538 |
0 |
| pdl *it = broadcast->pdls[j]; |
| 539 |
0 |
| it->dims[it->ndims-1] = broadcast->mag_nthr; |
| 540 |
0 |
| pdl_resize_defaultincs(it); |
| 541 |
0 |
| pdl_error PDL_err = pdl_make_physical(it); |
| 542 |
0 |
▶ | if (PDL_err.error) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PDL_err.error) { |
0 |
0 |
0 |
|
| 543 |
0 |
| *error_ret = PDL_err; |
| 544 |
0 |
| return 1; |
| 545 |
|
| } |
| 546 |
|
| } |
| 547 |
115 |
| pdl_error PDL_err = pdl_magic_thread_cast(broadcast->pdls[broadcast->mag_nthpdl], |
| 548 |
|
| func,t, broadcast); |
| 549 |
115 |
▶ | if (PDL_err.error) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PDL_err.error) { |
1 |
114 |
115 |
|
| 550 |
1 |
| *error_ret = PDL_err; |
| 551 |
1 |
| return 1; |
| 552 |
|
| } |
| 553 |
114 |
| broadcast->gflags &= ~PDL_BROADCAST_MAGICK_BUSY; |
| 554 |
114 |
| return 1; /* DON'T DO BROADCASTLOOP AGAIN */ |
| 555 |
|
| } |
| 556 |
|
| } |
| 557 |
|
| PDL_Indx *inds, *dims; int thr; |
| 558 |
44032 |
| PDL_Indx *offsp = pdl_get_threadoffsp_int(broadcast,&thr, &inds, &dims); |
| 559 |
44032 |
▶ | if (!offsp) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!offsp) return -1; |
0 |
44032 |
44032 |
|
| 560 |
132569 |
▶ | for (j=0; j<broadcast->ndims; j++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<broadcast->ndims; j++) |
89065 |
43504 |
132569 |
|
| 561 |
89065 |
▶ | if (!dims[j]) return 1; /* do nothing if empty */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dims[j]) return 1; /* do nothing if empty */ |
528 |
88537 |
89065 |
|
| 562 |
149620 |
▶ | for (j=0; j<npdls; j++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<npdls; j++) |
106116 |
43504 |
149620 |
|
| 563 |
106116 |
▶ | offsp[j] = PDL_BRC_THR_OFFSET(broadcast, thr, j); |
Branch: 3 branches
| Branch | True | False | Total |
| offsp[j] = PDL_BRC_THR_OFFSET(broadcast, thr, j); |
19971 |
86145 |
106116 |
| offsp[j] = PDL_BRC_THR_OFFSET(broadcast, thr, j); |
1367 |
104749 |
106116 |
| offsp[j] = PDL_BRC_THR_OFFSET(broadcast, thr, j); |
0 |
1367 |
1367 |
|
| 564 |
43504 |
| return 0; |
| 565 |
|
| } |
| 566 |
|
| |
| 567 |
|
| /* nth is how many dims are done inside the broadcastloop itself */ |
| 568 |
|
| /* inds is how far along each non-broadcastloop dim we are */ |
| 569 |
91511 |
| int pdl_iterbroadcastloop(pdl_broadcast *broadcast,PDL_Indx nth) { |
| 570 |
|
| int thr; |
| 571 |
91511 |
| PDL_Indx *inds, *dims, npdls = broadcast->npdls; |
| 572 |
91511 |
| PDL_Indx *offsp = pdl_get_threadoffsp_int(broadcast, &thr, &inds, &dims); |
| 573 |
91511 |
▶ | if (!offsp) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!offsp) return -1; |
0 |
91511 |
91511 |
|
| 574 |
91511 |
| return pdl_broadcast_nd_step(npdls, offsp, nth, broadcast->ndims, broadcast->incs, dims, inds); |
| 575 |
|
| } |