/* KDDKDDFREE Changed root to *root to allow NULL from ZOLTAN_FREE to propagate * KDDKDDFREE back to calling routine. */ int Zoltan_Oct_POct_delTree(OCT_Global_Info *OCT_info, pOctant *root) { int i; /* index counter */ pOctant child; /* child of an octant */ if(*root == NULL) return 1; if(Zoltan_Oct_isTerminal(*root)) { if(Zoltan_Oct_nRegions(*root)) Zoltan_Oct_clearRegions(*root); Zoltan_Oct_POct_free(OCT_info, root); } else { for(i=0; i<8; i++) { child = Zoltan_Oct_child(*root, i); if(child != NULL && Zoltan_Oct_POct_local(OCT_info,*root, i)) { Zoltan_Oct_POct_delTree(OCT_info,&child); /* KDDKDDFREE propagate NULL from Zoltan_Oct_POct_delTree to root->child */ (*root)->child[i] = NULL; (*root)->cpid[i] = -1; } /* KDDKDDFREE Added this condition so that tests (in other parts of the * KDDKDDFREE code) for NULL children work */ else if (child != NULL) { (*root)->child[i] = NULL; (*root)->cpid[i] = -1; } /* END KDDKDDFREE */ } Zoltan_Oct_POct_free(OCT_info, root); } return 1; }
/* * Zoltan_Oct_terminal_coarsen(oct) * * remove octant's children, accumulating regions * to octant * */ static void Zoltan_Oct_terminal_coarsen(ZZ *zz, OCT_Global_Info *OCT_info, pOctant oct) { pOctant child; /* child of an octant */ pRegion region; /* region associated with an octant */ int i; /* index counter */ pRegion regionlist[8]; /* an array of region lists */ oct_ncoarse++; /* increment coarsening counter */ for(i=0; i<8; i++) { /* get the ith child of an octant */ child = Zoltan_Oct_child(oct,i); /* cannot coarsen if child is off-processor */ /* if(!Zoltan_Oct_POct_local(child)) X */ /* cannot be off-processor */ if(!Zoltan_Oct_POct_local(OCT_info, oct, i)) { fprintf(stderr,"OCT Zoltan_Oct_terminal_coarsen: child not local\n"); abort(); } if(!Zoltan_Oct_isTerminal(child)) { fprintf(stderr,"OCT Zoltan_Oct_terminal_coarsen: child not terminal\n"); abort(); } /* get each child's region list */ regionlist[i] = Zoltan_Oct_regionlist(child); /* delete each child */ /* KDDKDDFREE Change child to &child. */ Zoltan_Oct_POct_free(OCT_info, &child); oct->child[i] = NULL; } oct->numChild = 0; /* * copy contents of each region list into region list * of coarsened parent (which is now a terminal octant) */ for(i=0; i < 8; i++) { region = regionlist[i]; /* go through the regionlist and add to octant */ while(region != NULL) { Zoltan_Oct_addRegion(zz, oct,region); region = region->next; } } }
static int Zoltan_Oct_Final_Migration( ZZ *zz, pOctant *octs, /* octs[nocts] */ int *newpids, /* newpids[nocts] */ pOctant *newocts, /* newocts[nocts] */ int nocts, /* number of octants leaving this processor */ int nrecocts) /* number of octants received in this processor */ { int i; Migrate_msg *msnd = NULL, *mrcv = NULL; int remotecount; int nsends; int nreceives; int *despid = NULL; int ierr = ZOLTAN_OK; ZOLTAN_COMM_OBJ *comm_plan; /* Object returned by communication routines */ char *yo = "Zoltan_Oct_Final_Migration"; OCT_Global_Info *OCT_info = (OCT_Global_Info *) zz->LB.Data_Structure; /* count number of sends */ nsends=0; for (i=0; i<nocts; i++) if (newpids[i]!=zz->Proc) nsends++; if((despid = (int *) ZOLTAN_MALLOC((nocts+10) * sizeof(int))) == NULL) { ZOLTAN_TRACE_EXIT(zz, yo); return ZOLTAN_MEMERR; } if((msnd = (Migrate_msg *) ZOLTAN_MALLOC((nocts+10) * sizeof(Migrate_msg))) == NULL) { ZOLTAN_TRACE_EXIT(zz, yo); ZOLTAN_FREE(&despid); return ZOLTAN_MEMERR; } remotecount = 0; for (i=0; i<nocts; i++) /* Send and free */ if (newpids[i]!=zz->Proc) { FILLMIGRATEMSG(octs[i], newocts[i], msnd[remotecount], zz->Proc); /* bug */ despid[remotecount++] = newpids[i]; Zoltan_Oct_clearRegions(octs[i]); /* KDDKDDFREE Change oct to &oct to allow NULL from ZOLTAN_FREE * KDDKDDFREE to propagate back. */ Zoltan_Oct_POct_free(OCT_info, &(octs[i])); } ierr = Zoltan_Comm_Create(&comm_plan, remotecount, despid, zz->Communicator, MigFinCommCreate, &nreceives); if(ierr != ZOLTAN_OK && ierr != ZOLTAN_WARN) { ZOLTAN_TRACE_EXIT(zz, yo); ZOLTAN_FREE(&despid); ZOLTAN_FREE(&msnd); return (ierr); } if((mrcv = (Migrate_msg *) ZOLTAN_MALLOC((nreceives+10) * sizeof(Migrate_msg))) == NULL) { ZOLTAN_TRACE_EXIT(zz, yo); ZOLTAN_FREE(&despid); ZOLTAN_FREE(&msnd); return ZOLTAN_MEMERR; } ierr = Zoltan_Comm_Do(comm_plan, MigFinCommDo, (char *) msnd, sizeof(Migrate_msg), (char *) mrcv); if(ierr != ZOLTAN_OK && ierr != ZOLTAN_WARN) { ZOLTAN_TRACE_EXIT(zz, yo); ZOLTAN_FREE(&despid); ZOLTAN_FREE(&msnd); ZOLTAN_FREE(&mrcv); return (ierr); } for (i=0; i<nreceives; i++) { /* Receive new parocts */ /* Zoltan_Oct_setID(mrcv[i].ptr,mrcv[i].id); */ /* Zoltan_Oct_POct_setparent(OCT_info, mrcv[i].ptr, mrcv[i].parent, mrcv[i].ppid); */ SETOCTFROMMIGRATEMSG(OCT_info, mrcv[i]); /* Zoltan_Oct_setchildnum(mrcv[i].ptr,mrcv[i].childnum); */ /* Zoltan_Oct_setchildren(mrcv[i].ptr, mrcv[i].children, mrcv[i].cpids); */ /* Zoltan_Oct_setbounds(mrcv[i].ptr, mrcv[i].min, mrcv[i].max); */ /* Zoltan_Oct_setDir(mrcv[i].ptr,mrcv[i].dir); */ /* Zoltan_Oct_setMapIdx(mrcv[i].ptr,mrcv[i].mapidx); */ } ierr = Zoltan_Comm_Destroy(&comm_plan); if(ierr != ZOLTAN_OK && ierr != ZOLTAN_WARN) { ZOLTAN_TRACE_EXIT(zz, yo); ZOLTAN_FREE(&despid); ZOLTAN_FREE(&msnd); ZOLTAN_FREE(&mrcv); return (ierr); } ZOLTAN_FREE(&despid); ZOLTAN_FREE(&msnd); ZOLTAN_FREE(&mrcv); return ierr; }