int main(int argc, char* argv[]) { cmdline::parser p; p.set_program_name("cnt"); p.add<size_t>("max", 'm', "Maximum nubmer of words to show", false, 0); p.add("reverse", 'r', "Reverse the result"); p.parse_check(argc, argv); size_t count = p.get<size_t>("max"); std::unordered_map<std::string, uint64_t> counts; std::string key; while (std::getline(std::cin, key)) { counts[key] += 1; } std::vector<std::pair<std::string, uint64_t> > pairs(counts.begin(), counts.end()); if (count == 0 || count > pairs.size()) { count = pairs.size(); } if (p.exist("reverse")) { sort_data(pairs, count, lower_second()); } else { sort_data(pairs, count, greater_second()); } for (std::size_t i = 0; i < count; ++i) { std::cout << pairs[i].second << '\t' << pairs[i].first << std::endl; } }
main() { Student class1[MAXST], *st; int i, j; void print_data(Student *st, int num, int order); void sort_data(Student *st, int num, int order); srand(time(NULL)); for( i=0 ; i<MAXST ; i++ ) { st = class1 + i; st->id = (rand() % 10) + IDBASE; st->point = rand() % 101; // 0 ~ 100 /* 학번 중복 검사 */ for( j=0 ; j<i ; j++ ) { if( st->id == class1[j].id ) { // 중복 --i; // 재시도를 위해서 break; // 중복검사 빠져나감 } } } print_data(class1, MAXST, NO_ORDER); // sort by point sort_data(class1, MAXST, PT_ORDER); // set order st = class1; st->order = 1; for( i=1 ; i<MAXST ; i++ ) { ++st; if( st->point == (st-1)->point ) st->order = (st-1)->order; else st->order = i+1; } print_data(class1, MAXST, PT_ORDER); // sort by id sort_data(class1, MAXST, ID_ORDER); print_data(class1, MAXST, ID_ORDER); }
void run_memtop(void) { //TODO: initialization for read and select fd_set rd; struct timeval timeout; int bytes; char buf[BUFFER_SIZE]; // Should I put this code insize FD_ISSET or where? // With if (fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK) == -1) { perror("fcntl()\n"); } //to avoid unused variable warning. You may remove it once you use buf. buf[0] = 0; while(1) { //TODO: call select, read, and process_data FD_ZERO(&rd); // Clear the fd set FD_SET(STDIN_FILENO,&rd); // Fill the fd set timeout.tv_sec = 0; // Waiting time is 0 timeout.tv_usec = 0; if (select(1,&rd,NULL,NULL,&timeout) == -1) { perror("select()"); } // Check if STDIN_FILENO ready or not if (FD_ISSET(STDIN_FILENO,&rd)) { // read up to BUFFER_SIZE bytes if ((bytes = read(STDIN_FILENO,buf,BUFFER_SIZE)) == -1) { perror("read()\n"); } if (process_input(buf,bytes) != 0) { break; } } //read proc filesystem int n_procs = 0; process_t *proc_arr = collect_data(&n_procs); if (proc_arr == NULL) { continue; } sort_data(proc_arr, n_procs); //update display display_data(proc_arr, n_procs); //free proc_data free(proc_arr); } }
void solver::do_solve() { //DrtPred question("--"); /// erase the question !!! string solver_options= wi_->getSolverOptions(); vector<Level> solved; vector<DrtVect> question_vect; question_vect.push_back(question_); vector<vector<clause_vector> > new_feet_clauses = get_relevant_clauses(question_vect); if(solver_options.find("simple") != string::npos) { new_feet_clauses= filter_simple_inference(new_feet_clauses); } if (new_feet_clauses.size() == 0 || (new_feet_clauses.size() != 0 && new_feet_clauses.at(0).size() == 0) ) { if (debug) puts("Empty Clauses!!"); return; } // cycles through the inferences steps int i; solved.clear(); vector<Level> lastData, data_list; if (debug) puts("Solving..."); path_memory mem; int n = 0; //set_clauses_unival(&new_feet_clauses, n+2); if (debug) print_vector(question_); lastData = launch_inference_threads(new_feet_clauses, question_vect, mem, k_, 1, 10, 1, n + 2); if (lastData.size() == 0) { if (debug) puts("Empty!!"); return; } DrtMgu upg; vector<path_memory> mem_vect; data_list.insert(data_list.end(), lastData.begin(), lastData.end()); sort_data(&data_list); Level current_layer; double last_layer_weight = 1; /// The following is necessary so that the clauses order in the first layer does not count!!! for (int m = 0; m < data_list.size(); ++m) { current_layer = data_list.at(m); vector<DrtVect> qvect = this->updateCurrentLayer(current_layer, question_); path_memory mem_tmp = current_layer.getMemory(); upg.clear(); vector<drt> tmp_drts; clock_t start; double w = is_match(qvect, &upg, &tmp_drts, mem_tmp); if(wi_->getTimeout() < 0 ) break; if (debug) cout << "SOLVER22:::" << w << endl; if (w != 0) { mem_tmp.last_upg(upg); mem_tmp.last_weigth(w); mem_tmp.setDrt(tmp_drts); mem_tmp.close(); if (this->areValidRules(mem_tmp)) mem_vect.push_back(mem_tmp); } } /// MULTIPLE LEVELS IN THE NEXT VERSION!!! (NOW IT IS TOO SLOW TO DEPLOY) // vector<Level> tmp_vect; // while ( data_list.size() && n < 3 ) { // current_layer= data_list.front(); // upg.clear(); // vector<drt> tmp_drts; // vector<DrtVect> qvect= this->updateCurrentLayer(current_layer,question_); // //vector<DrtVect> qvect= current_layer.getData(); // path_memory mem_tmp = current_layer.getMemory(); // double w=0; // if(mem_tmp.getDepth() > 0) // w = is_match(qvect, &upg, &tmp_drts, mem_tmp); // //bool add_new_clauses= true; // if( w != 0 ) { // mem_tmp.last_upg(upg); // mem_tmp.last_weigth(w); // mem_tmp.setDrt(tmp_drts); // mem_tmp.close(); // //if (this->areValidRules(mem_tmp)) { // //if(true) // //add_new_clauses = false; // mem_vect.push_back(mem_tmp); // //} // } // //else { // ///if(add_new_clauses) { // new_feet_clauses = get_relevant_clauses(qvect); // //new_feet_clauses= clauses_; // //} // ++n; // set_clauses_unival(&new_feet_clauses, n+2); // tmp_vect= launch_inference_threads(new_feet_clauses, qvect, current_layer.getMemory(), k_, 1, 10, 1, n+2); // if( tmp_vect.size() ) { // data_list.erase( data_list.begin() ); // tmp_vect.erase(tmp_vect.begin()+1, tmp_vect.end()); // data_list.insert(data_list.begin(), tmp_vect.begin(), tmp_vect.end() ); // sort_data(&data_list); // } // else { // data_list.erase( data_list.begin() ); // } // } ////// NEXT VERSION!!! solved_.clear(); if (mem_vect.size()) { int n; for (n = 0; n < mem_vect.size(); ++n) { DrtMgu upg_tmp = mem_vect.at(n).get_first_upg(); vector<DrtPred> solved_tmp(question_); solved_tmp / upg_tmp; double w = mem_vect.at(n).get_total_weigth(); path_memory mem_tmp = mem_vect.at(n); KnowledgeAnswer ka; ka.setPreds(solved_tmp); ka.setWeigth(w); ka.setLink(""); ka.setText(""); ka.setMemory(mem_tmp); // Update the Question list QuestionList tmp_qlist(qlist_); tmp_qlist / upg_tmp; ka.setQuestionList(tmp_qlist); solved_.push_back(ka); } } //sort_data(&solved_); }
int main(int argc, char **argv) { int events,kernel,i; int plot_type=PLOT_TYPE_START; int machine_num=0; double maxy; double average[NUM_FINAL_KERNELS],deviation[NUM_FINAL_KERNELS]; double median[NUM_FINAL_KERNELS],twentyfive[NUM_FINAL_KERNELS], seventyfive[NUM_FINAL_KERNELS]; long long *times=NULL; /* parse command line args */ if (argc<4) { printf("Must specify machine type, machine num, " "and start/stop/read/total\n"); exit(1); } machine_num=atoi(argv[2]); /* allocate memory */ times=calloc(NUM_FINAL_KERNELS*NUM_EVENTS*NUM_RUNS,sizeof(long long)); if (times==NULL) { fprintf(stderr,"Error allocating!\n"); return -1; } /* read in data */ plot_type=read_data(argv[1],machine_num,argv[3],FINAL_KERNELS, times); if (plot_type<0) { fprintf(stderr,"Some sort of error reading!\n"); return -1; } events=EVENT_TO_PLOT; /* sort data */ sort_data(times,events,FINAL_KERNELS); /* calculate median, twentyfive, seventyfive */ calculate_boxplot_data(times,events, median, twentyfive, seventyfive, FINAL_KERNELS); /* Calculate averages and deviation */ calculate_deviation(times,events,average,deviation,FINAL_KERNELS); /* calculate mins and maxes */ maxy=calculate_maxy(average,deviation,FINAL_KERNELS); /* Make graph */ printf("(* Begin Graph *)\n"); printf("newgraph\n"); printf("\n"); printf("X 6.5\n"); printf("Y 6.5\n"); printf("clip\n"); printf("\n"); printf("(* Legend *)\n"); printf("legend custom\n"); printf("\n"); printf("(* Y-Axis *)\n"); printf("yaxis size 4 min 0 max %.0f\n",maxy); printf("(* grid_gray 0.9 grid_lines *)\n"); printf("label font Helvetica fontsize %d : Average Overhead (Cycles)\n", FONTSIZE); printf("hash_labels font Helvetica fontsize %d\n",FONTSIZE); printf("\n"); printf("(* X-Axis *)\n"); printf("xaxis size 6.5 min %d max %d\n",-1,NUM_FINAL_KERNELS); //minx,maxx); printf("grid_gray 0.9 grid_lines\n"); printf("hash_labels font Helvetica fontsize %d vjc hjr rotate 45\n", FONTSIZE); printf("(* label font Helvetica fontsize %d : Kernels *)\n", FONTSIZE); printf("no_auto_hash_marks\n"); for(i=0;i<NUM_FINAL_KERNELS;i++) { printf("hash_at %d\n",i); } printf("no_auto_hash_labels\n"); for(i=0;i<NUM_FINAL_KERNELS;i++) { printf("hash_label at %d : %s\n",i,final_kernels[i].name); } printf("\n"); printf("(* Title *)\n"); printf("title font Helvetica fontsize %d y %lf : " "%s Overhead of ", FONTSIZE, (double)maxy+((double)maxy/8.0),argv[1]); if (plot_type==PLOT_TYPE_START) printf("Start"); if (plot_type==PLOT_TYPE_STOP) printf("Stop"); if (plot_type==PLOT_TYPE_READ) printf("Read"); if (plot_type==PLOT_TYPE_TOTAL) printf("Start/Stop/Read"); printf(" with %d Event%s\n",events,events==1?"":"s"); printf("\n"); for(kernel=0;kernel<NUM_FINAL_KERNELS;kernel++) { if (average[kernel]==0) { printf("newstring vjc x %d y %lf rotate 90 " "font Helvetica fontsize 16 lcolor ", kernel,maxy/10.0); if (final_kernels[kernel].type==INTERFACE_PERFCTR) { printf("1.0 0.0 0.0"); } else if (final_kernels[kernel].type==INTERFACE_PERFMON2) { printf("0.0 0.0 1.0"); } else if (final_kernels[kernel].type==INTERFACE_PERF_EVENT) { printf("0.0 0.0 0.0"); } else if (final_kernels[kernel].type==INTERFACE_PERF_EVENT_RDPMC) { printf("0.11 0.40 0.11"); } else { printf("0.3 0.3 0.0"); } printf(" : n/a\n"); continue; } /* plot standard deviation */ printf("newcurve "); if (final_kernels[kernel].type==INTERFACE_PERFCTR) { printf("marktype x linetype none color 1.0 0.0 0.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERFMON2) { printf("marktype x linetype none color 0.0 0.0 1.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERF_EVENT) { printf("marktype x linetype none color 0.0 0.0 0.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERF_EVENT_RDPMC) { printf("marktype x linetype none color 0.11 0.40 0.11\n"); } else { printf("marktype x linetype none color 0.3 0.3 0.0\n"); } printf("y_epts\n"); printf("\t%d %.2f %.2f %.2f (* %s standard dev *)\n", kernel,average[kernel], average[kernel]-deviation[kernel], average[kernel]+deviation[kernel], final_kernels[kernel].name); /* plot 25th to 75th box */ printf("newcurve "); printf("marktype box marksize 0.5 %lf linetype none ", seventyfive[kernel]-twentyfive[kernel]); if (final_kernels[kernel].type==INTERFACE_PERFCTR) { printf("color 1.0 0.0 0.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERFMON2) { printf("color 0.0 0.0 1.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERF_EVENT) { printf("color 0.0 0.0 0.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERF_EVENT_RDPMC) { printf("color 0.11 0.40 0.11\n"); } else { printf("color 0.3 0.3 0.0\n"); } printf("pts\n"); printf("\t%d %lf\n",kernel, (twentyfive[kernel]+seventyfive[kernel])/2.0); printf("\t(* %lf %lf %lf *)\n",median[kernel],twentyfive[kernel],seventyfive[kernel]); /* plot median */ printf("newcurve "); printf("marktype box marksize 0.5 1 linetype none color 1.0 1.0 1.0\n"); printf("pts\n"); printf("\t%d %lf\n",kernel,median[kernel]); /* plot outliers */ printf("newcurve "); if (final_kernels[kernel].type==INTERFACE_PERFCTR) { printf("marktype x linetype none color 1.0 0.0 0.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERFMON2) { printf("marktype x linetype none color 0.0 0.0 1.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERF_EVENT) { printf("marktype x linetype none color 0.0 0.0 0.0\n"); } else if (final_kernels[kernel].type==INTERFACE_PERF_EVENT_RDPMC) { printf("marktype x linetype none color 0.11 0.40 0.11\n"); } else { printf("marktype x linetype none color 0.3 0.3 0.0\n"); } printf("pts\n"); for(i=0;i<NUM_RUNS;i++) { if (*(get_runs(times,kernel,events)+i) > average[kernel] + deviation[kernel]) { printf("\t%d %lld\n",kernel, *(get_runs(times,kernel,events)+i)); } if (*(get_runs(times,kernel,events)+i) < average[kernel]-deviation[kernel]) { printf("\t%d %lld\n",kernel, *(get_runs(times,kernel,events)+i)); } } printf("\n"); } return 0; }
int main(int argc, char **argv) { int kernel,i,krg; int plot_type=PLOT_TYPE_START; int machine_num=0; double maxy; double average[NUM_READS][NUM_KERNELS],deviation[NUM_READS][NUM_KERNELS]; double median[NUM_READS][NUM_KERNELS],twentyfive[NUM_READS][NUM_KERNELS], seventyfive[NUM_READS][NUM_KERNELS]; long long *times=NULL; /* parse command line args */ if (argc<4) { printf("Must specify machine type, machine num, " "and start/stop/read/total\n"); exit(1); } machine_num=atoi(argv[2]); /* allocate memory */ times=calloc(NUM_MANYREAD_KERNELS*NUM_EVENTS*NUM_RUNS,sizeof(long long)); if (times==NULL) { fprintf(stderr,"Error allocating!\n"); return -1; } /* read in data */ /* default */ plot_type=read_data_many(argv[1],machine_num,argv[3],MANYREAD_KERNELS, times,1,0); /* For l1 cache misses */ // plot_type=read_data_many(argv[1],machine_num,argv[3],MANYREAD_KERNELS, // times,2,1); if (plot_type<0) { fprintf(stderr,"Some sort of error reading!\n"); return -1; } for(krg=0;krg<10;krg++) { /* sort data */ sort_data(times,krg,MANYREAD_KERNELS); /* calculate median, twentyfive, seventyfive */ calculate_boxplot_data(times,krg, median[krg], twentyfive[krg], seventyfive[krg], MANYREAD_KERNELS); /* Calculate averages and deviation */ calculate_deviation(times,krg,average[krg],deviation[krg], MANYREAD_KERNELS); } /* calculate mins and maxes */ maxy=calculate_maxy(average[0],deviation[0],MANYREAD_KERNELS); /* Make graph */ printf("(* Begin Graph *)\n"); printf("newgraph\n"); printf("\n"); printf("X 8.5\n"); printf("Y 6\n"); printf("clip\n"); printf("\n"); printf("(* Legend *)\n"); printf("legend custom\n"); printf("\n"); printf("(* Y-Axis *)\n"); printf("yaxis size 4 min 0 max %.0f\n",maxy); printf("(* grid_gray 0.9 grid_lines *)\n"); printf("label font Helvetica fontsize %d : Average Overhead (Cycles)\n", FONTSIZE); printf("hash_labels font Helvetica fontsize %d\n",FONTSIZE); printf("\n"); printf("(* X-Axis *)\n"); printf("xaxis size 6.5 min %d max %d\n",0,10); //minx,maxx); printf("grid_gray 0.9 grid_lines\n"); printf("hash_labels font Helvetica fontsize %d vjc hjr rotate 45\n", FONTSIZE); printf("(* label font Helvetica fontsize %d : Kernels *)\n", FONTSIZE); printf("no_auto_hash_marks\n"); for(i=0;i<NUM_MANYREAD_KERNELS;i++) { printf("hash_at %d\n",i); } printf("no_auto_hash_labels\n"); for(i=0;i<10;i++) { printf("hash_label at %d : %d\n",i,i+1); } printf("\n"); printf("(* Title *)\n"); printf("title font Helvetica fontsize %d y %lf : " "%s Overhead of ", FONTSIZE, (double)maxy+((double)maxy/8.0),argv[1]); if (plot_type==PLOT_TYPE_START) printf("Start"); if (plot_type==PLOT_TYPE_STOP) printf("Stop"); if (plot_type==PLOT_TYPE_READ) printf("Read"); if (plot_type==PLOT_TYPE_TOTAL) printf("Start/Stop/Read"); printf(" "); printf("\n"); for(krg=0;krg<10;krg++) { for(kernel=0;kernel<NUM_MANYREAD_KERNELS;kernel++) { /* plot standard deviation */ printf("newcurve "); if (kernel==0) { printf("marktype x linetype none color 0.0 0.0 0.0\n"); } else if (kernel==1) { printf("marktype x linetype none color 0.3 0.3 0.3\n"); } else { printf("marktype x linetype none color 0.3 0.3 0.0\n"); } printf("y_epts\n"); printf("\t%d %.2f %.2f %.2f (* %s standard dev *)\n", krg,average[krg][kernel], average[krg][kernel]-deviation[krg][kernel], average[krg][kernel]+deviation[krg][kernel], manyread_kernels[kernel].name); /* plot 25th to 75th box */ printf("newcurve "); printf("marktype box marksize 0.5 %lf linetype none ", seventyfive[krg][kernel]-twentyfive[krg][kernel]); if (kernel==0) { printf("color 0.0 0.0 0.0\n"); } else if (kernel==1) { printf("color 0.3 0.3 0.3\n"); } else { printf("color 0.3 0.3 0.0\n"); } printf("pts\n"); printf("\t%d %lf\n",krg, (twentyfive[krg][kernel]+seventyfive[krg][kernel])/2.0); printf("\t(* %lf %lf %lf *)\n",median[krg][kernel],twentyfive[krg][kernel],seventyfive[krg][kernel]); /* plot median */ printf("newcurve "); printf("marktype box marksize 0.5 1 linetype none color 1.0 1.0 1.0\n"); printf("pts\n"); printf("\t%d %lf\n",krg,median[krg][kernel]); /* plot outliers */ printf("newcurve "); if (kernel==0) { printf("marktype x linetype none color 0.0 0.0 0.0\n"); } else if (kernel==1) { printf("marktype x linetype none color 0.3 0.3 0.3\n"); } else { printf("marktype x linetype none color 0.3 0.3 0.0\n"); } printf("pts\n"); for(i=0;i<NUM_RUNS;i++) { if (*(get_runs(times,kernel,krg)+i) > average[krg][kernel] + deviation[krg][kernel]) { printf("\t%d %lld\n",krg, *(get_runs(times,kernel,krg)+i)); } if (*(get_runs(times,kernel,krg)+i) < average[kernel]-deviation[kernel]) { printf("\t%d %lld\n",krg, *(get_runs(times,kernel,krg)+i)); } } printf("\n"); } } return 0; }
void Power2NodesMPIRandomAccessUpdate(u64Int logTableSize, u64Int TableSize, s64Int LocalTableSize, u64Int MinLocalTableSize, u64Int GlobalStartMyProc, u64Int Top, int logNumProcs, int NumProcs, int Remainder, int MyProc, s64Int ProcNumUpdates, MPI_Datatype INT64_DT, MPI_Status *finish_statuses, MPI_Request *finish_req) { int i,j,k; int logTableLocal,ipartner,iterate,niterate,iter_mod; int ndata,nkeep,nsend,nrecv,nlocalm1, nkept; u64Int ran,datum,procmask; u64Int *data,*send,*send1,*send2; u64Int *recv[PITER][MAXLOGPROCS]; MPI_Status status; MPI_Request request[PITER][MAXLOGPROCS]; MPI_Request srequest; /* setup: should not really be part of this timed routine */ data = (u64Int *) malloc(CHUNKBIG*sizeof(u64Int)); send1 = (u64Int *) malloc(CHUNKBIG*sizeof(u64Int)); send2 = (u64Int *) malloc(CHUNKBIG*sizeof(u64Int)); send = send1; for (j = 0; j < PITER; j++) for (i = 0; i < logNumProcs; i++) recv[j][i] = (u64Int *) malloc(sizeof(u64Int)*RCHUNK); ran = HPCC_starts(4*GlobalStartMyProc); niterate = ProcNumUpdates / CHUNK; logTableLocal = logTableSize - logNumProcs; nlocalm1 = LocalTableSize - 1; /* actual update loop: this is only section that should be timed */ for (iterate = 0; iterate < niterate; iterate++) { iter_mod = iterate % PITER; for (i = 0; i < CHUNK; i++) { ran = (ran << 1) ^ ((s64Int) ran < ZERO64B ? POLY : ZERO64B); data[i] = ran; } nkept = CHUNK; nrecv = 0; if (iter_mod == 0) for (k = 0; k < PITER; k++) for (j = 0; j < logNumProcs; j++) { ipartner = (1 << j) ^ MyProc; MPI_Irecv(recv[k][j],RCHUNK,INT64_DT,ipartner,0,MPI_COMM_WORLD, &request[k][j]); } for (j = 0; j < logNumProcs; j++) { nkeep = nsend = 0; send = (send == send1) ? send2 : send1; ipartner = (1 << j) ^ MyProc; procmask = ((u64Int) 1) << (logTableLocal + j); if (ipartner > MyProc) { sort_data(data,data,send,nkept,&nkeep,&nsend,logTableLocal+j); if (j > 0) { MPI_Wait(&request[iter_mod][j-1],&status); MPI_Get_count(&status,INT64_DT,&nrecv); sort_data(recv[iter_mod][j-1],data,send,nrecv,&nkeep, &nsend,logTableLocal+j); } } else { sort_data(data,send,data,nkept,&nsend,&nkeep,logTableLocal+j); if (j > 0) { MPI_Wait(&request[iter_mod][j-1],&status); MPI_Get_count(&status,INT64_DT,&nrecv); sort_data(recv[iter_mod][j-1],send,data,nrecv,&nsend, &nkeep,logTableLocal+j); } } if (j > 0) MPI_Wait(&srequest,&status); MPI_Isend(send,nsend,INT64_DT,ipartner,0,MPI_COMM_WORLD,&srequest); if (j == (logNumProcs - 1)) update_table(data,HPCC_Table,nkeep,nlocalm1); nkept = nkeep; } if (logNumProcs == 0) update_table(data,HPCC_Table,nkept,nlocalm1); else { MPI_Wait(&request[iter_mod][j-1],&status); MPI_Get_count(&status,INT64_DT,&nrecv); update_table(recv[iter_mod][j-1],HPCC_Table,nrecv,nlocalm1); MPI_Wait(&srequest,&status); } ndata = nkept + nrecv; } /* clean up: should not really be part of this timed routine */ for (j = 0; j < PITER; j++) for (i = 0; i < logNumProcs; i++) free(recv[j][i]); free(data); free(send1); free(send2); }
void freepsgold(int* sampsize, double* xdata, double* ydata, int* ord, int* numknot, int* initseed, int* initstream, double* lambda, double* optknot, double* trace_hat, double* GCV, double* GSJS_value) { int i, order, n, nobs, inform, seed, stream; double bestlambda; double shift, scale; struct L2_1D_DATA * origdat, * sortdat; struct SP_1D * best_sp; /* set order and dimension for spline, seed, and stream */ order = *ord; n = *numknot; n += order; seed = *initseed; stream = *initstream; /* load data into data struct */ origdat = data_1d_initialize(*sampsize, &inform); for(i=0; i<*sampsize; i++) { origdat->xdata[i] = xdata[i]; origdat->ydata[i] = ydata[i]; } nobs = origdat->nobs; sortdat = data_1d_initialize(nobs, &inform); dat_psgold = data_1d_initialize(nobs, &inform); sort_data(origdat, sortdat); scale_data(sortdat, dat_psgold, &shift, &scale); sp_psgold = sp_1d_initialize( order, n, &inform); sp_1d_set_knots(sp_psgold, 0., 1.); best_sp = sp_1d_initialize( order, n, &inform); sp_1d_set_knots(best_sp, 0., 1.); bestlambda = slave_psgold(shift, scale, seed, stream); /* Save information */ /* Lambda */ *lambda = bestlambda * pow(scale, 2*sp_psgold->order-2); /* Optimal knots */ for (i = 0; i <*numknot; i++) optknot[i] = shift + scale * sp_psgold->knot[i+*ord]; /* trace of hat matrix */ *trace_hat = trace_hat_matrix(dat_psgold, sp_psgold, bestlambda); /* GCV */ *GCV = gcv(dat_psgold, sp_psgold, bestlambda, MIN_SPACE_PSGOLD); /* GSJS */ *GSJS_value = GSJS(dat_psgold); }