Skip to content

Commit

Permalink
add pdl.ntrans_children to speed up destroying ndarrays - #421 #451
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 31, 2024
1 parent f7b9469 commit 91802e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Basic/Core/pdl.h.PL
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ struct pdl {
void *hdrsv; /* "header", settable from Perl */
PDL_Value value; /* to store at least one value */
PDL_Indx ntrans_children; /* CORE21 put next to other trans-tracking stuff */
};
typedef struct pdl_slice_args {
Expand All @@ -563,20 +564,22 @@ typedef struct pdl_slice_args {
* Some macros for looping over the trans_children of a given PDL
*/
#define PDL_DECL_CHILDLOOP(p) \
int p##__i; pdl_trans_children *p##__c;
int p##__i; pdl_trans_children *p##__c; PDL_Indx p##__unfound;
#define PDL_START_CHILDLOOP(p) \
p##__c = &p->trans_children; \
do { \
for(p##__i=0; p##__i<PDL_NCHILDREN; p##__i++) { \
if(p##__c->trans[p##__i]) {
p##__c = &p->trans_children; p##__unfound = p->ntrans_children; \
do { \
if (p##__unfound <= 0) break; \
for (p##__i=0; p##__i<PDL_NCHILDREN; p##__i++) { \
if (p##__c->trans[p##__i]) { \
p##__unfound--;
#define PDL_CHILDLOOP_THISCHILD(p) p##__c->trans[p##__i]
#define PDL_END_CHILDLOOP(p) \
} \
} \
if(!p##__c) break; \
if(!p##__c->next) break; \
p##__c=p##__c->next; \
} while(1);
} \
} \
if (!p##__c) break; \
if (!p##__c->next) break; \
p##__c=p##__c->next; \
} while (1);
#define PDL_USESTRUCTVALUE(it) \
(it->nbytes <= sizeof(it->value))
Expand Down
4 changes: 4 additions & 0 deletions Basic/Core/pdlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pdl* pdl_pdlnew() {
PDL_Indx i;
for(i=0; i<PDL_NCHILDREN; i++) {it->trans_children.trans[i]=NULL;}
it->trans_children.next = NULL;
it->ntrans_children = 0;
it->magic = 0;
it->hdrsv = 0;
PDLDEBUG_f(printf("pdl_pdlnew %p (size=%zu)\n",(void*)it,sizeof(pdl)));
Expand Down Expand Up @@ -303,6 +304,7 @@ void pdl__removetrans_children(pdl *it,pdl_trans *trans)
if (PDL_CHILDLOOP_THISCHILD(it) != trans) continue;
PDL_CHILDLOOP_THISCHILD(it) = NULL;
flag = 1;
it->ntrans_children--;
/* Can't return; might be many times (e.g. $x+$x) */
PDL_END_CHILDLOOP(it)
/* this might be due to a croak when performing the trans; so
Expand Down Expand Up @@ -602,6 +604,7 @@ pdl_error pdl__addchildtrans(pdl *it,pdl_trans *trans)
if (c->next) { c=c->next; continue; } else {
for(i=0; i<PDL_NCHILDREN; i++)
if(! c->trans[i]) {
it->ntrans_children++;
c->trans[i] = trans; return PDL_err;
}
break;
Expand All @@ -610,6 +613,7 @@ pdl_error pdl__addchildtrans(pdl *it,pdl_trans *trans)
c = c->next = malloc(sizeof(pdl_trans_children));
if (!c) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
c->trans[0] = trans;
it->ntrans_children++;
for(i=1; i<PDL_NCHILDREN; i++)
c->trans[i] = 0;
c->next = 0;
Expand Down
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- fix 64-bit problem in Minuit revealed by LTO (#468) - thanks @eli-schwartz for report
- add pdl.ntrans_children to speed up destroying ndarrays (#421,#451)

2.085_02 2024-03-25
- PP add loop(n=value) idiom to start not at 0
Expand Down

0 comments on commit 91802e9

Please sign in to comment.