// Focus on a certain chunk, superchunk of dpB is in the position pos in dpA // Generate a new DECOMP dp DECOMP *decomp_focus(DECOMP *dpA, int pos, DECOMP *dpB) { // Dimension of dp and way to decompose is the same as dpB DECOMP *dp = decomp_new(dpB->row, dpB->col, dpB->row_nchunks, dpB->col_nchunks); // Compute new offsets int lr, lc, or, oc; decomp_get_pos(dpA, pos, &lr, &lc, &or, &oc); // New offset = // offset of dpA in its superchunk + // offset of dpB's superchunk in dpB + // offset of dpB in its superchunk dp->orowg = dpA->orowg + or + dpB->orowg; dp->ocolg = dpA->ocolg + oc + dpB->ocolg; return dp; }
int Restart_read_driver(char *dmpname, int mdmpflag, int memflag) { char *me = "Restart_read_driver"; char *kern, *rem, *infostr; char msg[MAXLINE]; int i, error = 0, ierr; int num, mycyc, iblk, gblk, namelen; int mynblk; int numBlocks, numDomains; int *domainFiles; DBfile *idbid; RGST_AttributeElem_t *func; if (memflag == 1) { memclr() ; } comlock(dmp_nbaton); if (mdmpflag) { kern = strtok(dmpname,"-"); rem = strtok(NULL,"-"); mycyc = atoi(rem); RestartCycle = mycyc; strcpy(RestartKernel,kern); rootfile_read(kern,mycyc); } else { namelen = strlen(dmpname); if (namelen > 10) { memset(msg,'\0',MAXLINE); strncpy(RestartKernel,dmpname,namelen - 10); RestartKernel[namelen - 9] = '\0'; i = strlen(dmpname) - 10; strncpy(msg,&(dmpname[i]), 5); RestartCycle = atoi(msg); } else { } idbid = DBOpen (dmpname, DB_PDB, DB_READ); if (idbid == NULL) { error = 1 ; sprintf(msg,"Can't open dump %s\n",dmpname); ctlwarning(me,msg); return(error) ; } infostr = DBGetVar (idbid, "_fileinfo"); namelen = strlen(codename); if (strncmp (infostr, codename, namelen) != 0) { sprintf(msg,"Restarting from a dump which is not %s. This is EVIL!\n", codename); ctlwarning(me,msg); } FREEMEM(infostr); decomp_setdir(idbid); ierr = DBReadVar(idbid,"NumBlocks",&numBlocks); ierr += DBReadVar(idbid,"NumDomains",&numDomains); if (ierr != 0) ctlerror(me,gv_errmsg_DBReadVar); decomp_new(numBlocks, numDomains); decomp_read(idbid, msg, 0, 0); if (DBSetDir(idbid, "/") != 0) ctlerror(me,gv_errmsg_DBSetDir); error += Restart_read_global(idbid); dmpattr_set(); domainFiles = MALLOT(int, gnblk); for (gblk = 0; gblk < gnblk; gblk++) { domainFiles[gblk] = gmap[gblk].lblk; } calculate_mappings(); mynblk = 0; for (gblk = 0; gblk < gnblk; gblk++) { if (gmap[gblk].proc != myid) continue; iblk = gmap[gblk].lblk; Restart_read_domain(idbid, domainFiles[gblk], iblk); mynblk++; } nblk = mynblk; DBClose(idbid); FREEMEM(domainFiles); } dmpattr_unset(); comunlock(dmp_nbaton); ifparallel = 0; nblk = gnblk; initcom(NULL,0); sprintf(msg,"dump '%s' read",dmpname); ctlmsg(msg); printtc() ; func = rgst_list_attr(A_OBJECT, "Function_Gen"); while (func != NULL) { Command_t *cp = (Command_t *) func->rgst_obj->obj; (*(cp->proc))(); func = func->next; } blknum = 0 ; genmd = -1; error += qbnd(FULL_STEP,COM_RECV); error += qbnd(FULL_STEP,COM_SEND); error += qbnd(FULL_STEP,COM_WAIT_RECV); TimeStepControl_initialize() ; for ( iblk = 0 ; iblk < nblk ; iblk++ ) { updateblk( &domains[iblk], 0, 0.0 ) ; } ; error += qbnd(FULL_STEP,COM_WAIT_SEND); editor(FULL_STEP); genmd = 0; hash_optimize_all(); return(0); }
int main() { int row = 4, col = 6; int nbuckets = 40; int hist_ratio = 5; int period = 2; int i, j; float data1[4 * 6] = {1.1, 2.5, 3.6, 1.5, 2.9, 3.5, 0.7, 2.1, 2.7, 3.9, 2.2, 1.4, 3.5, 1.5, 0.2, 1.3, 2.6, 3.1, 0.3, 1.7, 0.9, 3.2, 2.8, 2.6}; float data2[4 * 6] = {1.0, 2.5, 3.7, 1.4, 2.6, 3.7, 0.4, 2.3, 2.8, 3.9, 2.0, 1.5, 3.1, 1.0, 0.3, 1.3, 2.8, 3.4, 0.6, 1.9, 0.8, 3.1, 2.4, 0.2}; float low = 0, high = 1.0; int row_nchunks = 2; int col_nchunks = 6; int result[row * col]; int count; float chunk[period*col*row]; DECOMP *dp; RETRIEVER *rp; YANDEX *yp; // Init dp = decomp_new(row, col, row_nchunks, col_nchunks); rp = retriever_new(dp, period); yp = yandex_new(rp, nbuckets, hist_ratio, NULL); // Start a period yandex_start(yp); // Feed data retriever_feed(rp, data1); yandex_update(yp); retriever_feed(rp, data2); yandex_update(yp); // Stop a period yandex_stop(yp); // Query int chunksize; int nexact, nfuzzy; int okflag; yandex_query(yp, low, high, result, &count, YANDEX_IN); buckets_print(yp->bp); printf("=======================================================\n"); printf("Query range: %.2f -- %.2f\n", low, high); printf("Result(%d)\n", count); for (i = 0; i < count; i++) { printf("%2d ", result[i]); } printf("\n"); for (i = 0; i < count; i++) { chunksize = retriever_get_chunk(rp, result[i], chunk); printf("Pos %2d[%d]: ", result[i], chunksize); for (j = 0; j < chunksize; j++) { if (j%(col/col_nchunks) == 0) printf("\n"); printf("%.2f ", chunk[j]); } printf("\n\n"); } okflag = yandex_verify(yp, low, high, result, count, &nexact, &nfuzzy, 1, YANDEX_IN); low = -1; high = 3; yandex_query(yp, low, high, result, &count, YANDEX_NOT_IN); printf("=======================================================\n"); printf("Query not in range: %.2f -- %.2f\n", low, high); printf("Result(%d)\n", count); for (i = 0; i < count; i++) { printf("%2d ", result[i]); } printf("\n"); for (i = 0; i < count; i++) { chunksize = retriever_get_chunk(rp, result[i], chunk); printf("Pos %2d[%d]: ", result[i], chunksize); for (j = 0; j < chunksize; j++) { if (j%(col/col_nchunks) == 0) printf("\n"); printf("%.2f ", chunk[j]); } printf("\n\n"); } okflag = yandex_verify(yp, low, high, result, count, &nexact, &nfuzzy, 1, YANDEX_NOT_IN); decomp_free(dp); retriever_free(rp); yandex_free(yp); return 0; }