void test_list(void) { struct histogram *hist1 = histogram_create("hist1"); struct histogram *hist2 = histogram_create("hist2"); struct histogram *hist3 = aim_zmalloc(sizeof(*hist3)); histogram_register(hist3, "hist3"); AIM_ASSERT(!strcmp(hist1->name, "hist1")); AIM_ASSERT(!strcmp(hist2->name, "hist2")); AIM_ASSERT(!strcmp(hist3->name, "hist3")); struct list_head *head = histogram_list(); struct list_links *cur = list_first(head); AIM_ASSERT(container_of(cur, links, struct histogram) == hist1); cur = cur->next; AIM_ASSERT(container_of(cur, links, struct histogram) == hist2); cur = cur->next; AIM_ASSERT(container_of(cur, links, struct histogram) == hist3); AIM_ASSERT(cur->next == &head->links); histogram_destroy(hist1); histogram_destroy(hist2); histogram_unregister(hist3); aim_free(hist3); }
void test_basic(void) { struct histogram *hist = histogram_create("basic"); check(hist, 0, 0); histogram_inc(hist, 0); check(hist, 0, 1); histogram_inc(hist, 0); check(hist, 0, 2); /* 1 is a different bucket */ histogram_inc(hist, 1); check(hist, 1, 1); /* 32 and 33 are the same bucket */ histogram_inc(hist, 32); histogram_inc(hist, 33); check(hist, 32, 2); check(hist, 33, 2); histogram_inc(hist, UINT32_MAX); check(hist, UINT32_MAX, 1); histogram_destroy(hist); }
void test_all(void) { struct histogram *hist = histogram_create("all"); uint32_t k; for (k = 0; k < UINT32_MAX; k++) { check(hist, k, 0); } check(hist, k, 0); for (k = 0; k < UINT32_MAX; k++) { histogram_inc(hist, k); } histogram_inc(hist, k); for (k = 0; k < 16; k++) { check(hist, k, 1); } int i; for (i = 4; i < 32; i++) { uint32_t c = (1u << i) / 16; for (k = 1<<i; k < (2<<i) - 1; k++) { check(hist, k, c); } check(hist, k, c); } histogram_destroy(hist); }
void test_find(void) { AIM_ASSERT(histogram_find("hist1") == NULL); AIM_ASSERT(histogram_find("hist2") == NULL); struct histogram *hist1 = histogram_create("hist1"); AIM_ASSERT(histogram_find("hist1") == hist1); AIM_ASSERT(histogram_find("hist2") == NULL); struct histogram *hist2 = histogram_create("hist2"); AIM_ASSERT(histogram_find("hist1") == hist1); AIM_ASSERT(histogram_find("hist2") == hist2); histogram_destroy(hist1); AIM_ASSERT(histogram_find("hist1") == NULL); AIM_ASSERT(histogram_find("hist2") == hist2); histogram_destroy(hist2); AIM_ASSERT(histogram_find("hist1") == NULL); AIM_ASSERT(histogram_find("hist2") == NULL); }
/* * Read the "pages per bulk r/w" histogram from the * brw_stats file. Then sum rpc counts from all of the * histogram bins, including both reads and writes, * into a single number representing all bulk RPCs * that this target has handled. ltop calls these * "IOPs". */ static int _get_iops (pctx_t ctx, char *name, uint64_t *iopsp) { histogram_t *h; int i; uint64_t iops = 0; if (proc_lustre_brwstats (ctx, name, BRW_RPC, &h) < 0) return -1; for (i = 0; i < h->bincount; i++) iops += h->bin[i].yr + h->bin[i].yw; histogram_destroy (h); *iopsp = iops; return 0; }
int main(int argc, char * argv[]) { //============================================ // Set input parameters if (argc < 4|| argc > 4){ printf("Wrong number of inputs. You entered %d. You should enter 4\n.", argc); myusage(); } int XLENGTH = atoi(argv[1]); int YLENGTH = atoi(argv[2]); int NCLUST = atoi(argv[3]); int HLENGTH; double px[XLENGTH]; double py[YLENGTH]; double beta = .00001; double F; double infocurve[4] = {1,1,1,1}; //int modus = 0; // modus = 0 : use p(y|c) cluster centers as initialization // modus = 1 : use p(c|x) assignment ruls as initialization double annealingrate = 1.1; bool plotme = true; //some debug printing bool debug = false;//verbose debug printing FILE * histFile; FILE * probFile; histogram_t *histo; histogram_t *pxy; histogram_t *pygc; histogram_t *pcgx; histogram_t *pc; if(plotme) { printf("XLENGTH= %d\n", XLENGTH); printf("YLENGTH= %d\n", YLENGTH); printf("NCLUST = %d\n", NCLUST); } histFile = fopen(histoName, "r"); if(histFile == NULL) { printf("Error: can't access %s\n", histoName); exit(1); } float v; int j,i = 0; int y; int x; char s [YLENGTH*20]; char * tok; // //allocate memory for large cluster probability arrays // double** pygc; // //allocate pointer memory for first dimension // pygc = (double**)malloc(YLENGTH*sizeof(double)); // if(NULL == pygc){free(pygc); printf("Memory allocation failed while allocating for pygc[].\n"); exit(-1);} // // /*allocate memory for second dimension */ // for(i = 0; i < YLENGTH;i++) // { // pygc[i] = (double *) malloc( NCLUST * sizeof(double) ); // if(NULL == pygc[i]){free(pygc[i]); printf("Memory allocation failed while allocating for matrix[x][].\n"); exit(-1);} // } // // double** pcgx; // //allocate pointer memory for first dimension // pcgx = (double**)malloc(NCLUST*sizeof(double)); // if(NULL == pcgx){free(pcgx); printf("Memory allocation failed while allocating for pcgx[].\n"); exit(-1);} // // /*allocate memory for second dimension */ // for(i = 0; i < NCLUST;i++) // { // pcgx[i] = (double *) malloc( XLENGTH * sizeof(double) ); // if(NULL == pcgx[i]){free(pcgx[i]); printf("Memory allocation failed while allocating for matrix[x][].\n"); exit(-1);} // } //count how many entries are actually in the histogram file -- these are only the non-zero p(y|x) while(fscanf(histFile, "%f", &v)!= EOF) { i++; } rewind(histFile); if(debug){printf("Counted %d entries in histogram file\n", i);} //make histogram size 1/2 number entries counted because 1/2 are the indices (y values) HLENGTH = i/2; histo = histogram_create(HLENGTH); x = 0; //make p(y|x) histogram //YLENGTH*20 is assuming most words are less than 20 chars long while(fgets(s, (YLENGTH*20), histFile)!= NULL) { tok = strtok(s,"\t"); while(tok != NULL) { if(debug){printf("Found word: %d\n", atoi(tok));} y = atoi(tok); tok = strtok(NULL, "\t"); if(tok != NULL) //hits null in the word { if(debug){printf("Found value: %f\n", atof(tok));} v = atof(tok); tok = strtok(NULL, "\t"); histogram_set(histo,x,y,v); } } x++; } if(debug) { printf("Checking histogram\n"); for(x = 0; x < XLENGTH; x++) { for(y = 0; y < YLENGTH; y++) { if((v = histogram_get(histo, x, y))) { printf("Found doc %d - word %d in histo: %f\n",x,y,v); } } } } fclose(histFile); // now read in the other initial probs probFile = fopen(probName, "r"); if(probFile == NULL) { printf("Error: can't access %s\n", histoName); exit(1); } //*********** p(x) is first line ******************* printf("read in p(x)\n"); fgets(s, (XLENGTH*20), probFile); //printf("s = %s\n",s); // printf("length of s = %d\n", strlen(s)); tok = strtok(s,"\t"); x = 0; while(tok != NULL) { //printf("tok = %s\n", tok); if(strcmp(tok,"\n") != 0) { px[x] = atof(tok); //printf("px(%d) = %f\n", x, px[x]); x++; } tok = strtok(NULL,"\t"); } //second line is blank fgets(s, (YLENGTH*20), probFile); //************** p(y) is third line ************************ fgets(s, (YLENGTH*20), probFile); printf("read in p(y)\n"); // printf("s = %s\n",s); // printf("length of s = %d\n", strlen(s)); tok = strtok(s,"\t"); x = 0; while(tok != NULL) { if(strcmp(tok,"\n") != 0) { py[x] = atof(tok); // printf("py(%d) = %f\n", x, py[x]); x++; } tok = strtok(NULL,"\t"); } //fourth line is blank fgets(s,(YLENGTH*20), probFile); //******************** fifth line on is p(xy) printf("Making p(x;y)\n"); pxy = histogram_create(HLENGTH); x = 0; while(fgets(s, (YLENGTH*20), probFile)!= NULL) { //get line for doc //printf("Found %s\n", s); //split y and p tok = strtok(s,"\t"); while(tok != NULL) { //printf("Found word: %d\n", atoi(tok)); y = atoi(tok); tok = strtok(NULL, "\t"); if(tok != NULL) //hits null in the word { //printf("Found value: %f\n", atof(tok)); v = atof(tok); tok = strtok(NULL, "\t"); histogram_set(pxy,x,y,v); } } x++; } fclose(probFile); if(debug){ printf("Checking pxy\n"); for(x = 0; x < XLENGTH; x++) { for(y = 0; y < YLENGTH; y++) { if((v = histogram_get(pxy, x, y))) { printf("Found doc %d - word %d in histo: %f\n",x,y,v); } } } } //****************** initialize cluster probs ***************************** printf("Making p(c|x)\n"); ini_pcgx(NCLUST, XLENGTH, pcgx); printf("Now going to anneal\n"); //******************* NOW GO TO ANNEAL ************************** F = anneal(XLENGTH, YLENGTH, NCLUST, beta, pxy, histo, pcgx, pygc, pc, infocurve, annealingrate, plotme); printf("Returned from anneal\n"); //cleanup histogram_destroy(pxy); histogram_destroy(histo); histogram_destroy(pygc); histogram_destroy(pcgx); histogram_destroy(pc); // for(i = 0; i < YLENGTH; i++) // free(pygc[i]); // free(pygc); // for(i = 0; i < NCLUST; i++) // free(pcgx[i]); // free(pcgx); exit(1); }