void write_float64_n(const char *id, double* buf, int buf_len) { int i; for(i = 0; i < buf_len; i++) { write_float64((char*) id,buf[i]); } }
void Sender(char* infile_arg) { double sigma; int SI, idx; for(SI = 0; SI < NSIGMAS; SI++) { __HF__(0,SI,_hF0); } fprintf(stderr," Sent hF0.\n"); for(SI = 0; SI < NSIGMAS; SI++) { __HF__(1,SI,_hF1); } fprintf(stderr," Sent hF1.\n"); for(SI = 0; SI < NSIGMAS; SI++) { __HF__(2,SI,_hF2); } fprintf(stderr," Sent hF2.\n"); for(SI = 0; SI < NSIGMAS; SI++) { __HF__(3,SI,_hF3); } fprintf(stderr," Sent hF3.\n"); for(SI = 0; SI < NSIGMAS; SI++) { __HF__(4,SI,_hF4); } fprintf(stderr," Sent hF4.\n"); for(SI = 0; SI < NSIGMAS; SI++) { __HF__(5,SI,_hF5); } fprintf(stderr," Sent hF5.\n"); fprintf(stderr," Hermite Function Initiation complete.\n"); FILE* frec = fopen(infile_arg, "r"); if(frec == NULL) { fprintf(stderr, "could not open the record file %s\n", infile_arg); return; } double data; fscanf(frec, "%lf", &data); while(!feof(frec)){ write_float64("det_input_pipe", data); fscanf(frec, "%lf", &data); } fclose(frec); }
void bestFit() { initHF(); while(1) { // uint32_t start_time = getClockTime(); // read in the samples one by one. // for each sample, simultaneously calculate // the incremental inner product across all the hF polynomials. RxAndComputeInnerProducts(); // At this point you have the projections. Calculate // MSE for each projection.. computeMSE(); // At this point, we have the best SI. double SI = best_sigma_index; write_float64("out0_data", SI); // write_float64("out1_data", dotP0[0]); int I; write_float64("out1_data", dotP0[best_sigma_index]); write_float64("out1_data", dotP1[best_sigma_index]); write_float64("out1_data", dotP2[best_sigma_index]); write_float64("out1_data", dotP3[best_sigma_index]); write_float64("out1_data", dotP4[best_sigma_index]); write_float64("out1_data", dotP5[best_sigma_index]); // } // uint32_t end_time = getClockTime(); // write_uint32("elapsed_time_pipe", (end_time - start_time)); initFit(); } }
int start(void) #endif { int i; uint32_t apl; float ong; uint64_t apl64; uint16_t apl16; uint8_t apl8; void* ptr; double ong64; for (i = 0; i < 10; ++i) { apl64 = read_uint64("apples64"); #ifdef RUN fprintf(stderr, "\n(%d.a) got a 64 bit apple: %llu..", i, apl64); #endif ong64 = (double)apl64; write_float64("oranges64", ong64); #ifdef RUN fprintf(stderr, "\nsent a (double) orange: %le.", ong64); #endif apl = read_uint32("apples32"); #ifdef RUN fprintf(stderr, "\n(%d.b) got a 32-bit apple: %d.", i, apl); #endif ong = (float)apl; write_float32("oranges32", ong); #ifdef RUN fprintf(stderr, "\nsent a (float) orange: %f.", ong); #endif apl16 = read_uint16("apples16"); #ifdef RUN fprintf(stderr, "\n(%d.c) got a 16-bit apple: %d.", i, apl16); #endif apl8 = (uint8_t)apl; write_uint8("oranges8", apl8); #ifdef RUN fprintf(stderr, "\nsent an 8-bit orange: %d.", apl8); #endif ptr = read_pointer("apples32"); #ifdef RUN fprintf(stderr, "\n(%d.d) got a pointer apple: %d.", i, (unsigned int) ptr); #endif write_pointer("oranges32", ptr); #ifdef RUN fprintf(stderr, "\nsent a pointer orange: %d.", (unsigned int) ptr); #endif } #ifdef RUN fprintf(stderr, "\n"); #endif return 0; }
int main(int argc, char* argv[]) { float result; int I; if(argc < 2) { fprintf(stderr,"Supply data set file.\n"); return(1); } FILE* fp = fopen(argv[1],"r"); if(fp == NULL) { fprintf(stderr,"Could not open data set file %s.\n", argv[1]); return(1); } signal(SIGINT, Exit); signal(SIGTERM, Exit); PTHREAD_DECL(Logger); PTHREAD_CREATE(Logger); #ifdef SW init_pipe_handler(); PTHREAD_DECL(bestFit); PTHREAD_CREATE(bestFit); #endif Sender(); for(I = 0; I < NSAMPLES; I++) { double X; fscanf(fp, "%le", &X); write_float64("sample_data_pipe", X); samples[I] = X; } fprintf(stderr," Sent samples.\n"); fclose(fp); calculateReferenceFit(); uint32_t best_sigma_index = read_uint32("best_sigma_pipe"); fprintf(stdout, " Best sigma= %f (index = %d).\n", (MIN_SIGMA + (best_sigma_index*(MAX_SIGMA - MIN_SIGMA)/NSIGMAS)), best_sigma_index); double p0 = read_float64("fit_coefficient_pipe"); double p1 = read_float64("fit_coefficient_pipe"); double p2 = read_float64("fit_coefficient_pipe"); double p3 = read_float64("fit_coefficient_pipe"); double p4 = read_float64("fit_coefficient_pipe"); double p5 = read_float64("fit_coefficient_pipe"); fprintf(stdout, "Fit coefficients = %le, %le, %le, %le, %le, %le.\n", p0,p1,p2,p3,p4,p5); uint32_t elapsed_time = read_uint32("elapsed_time_pipe"); fprintf(stdout,"Elapsed time = %d.\n", elapsed_time); #ifdef SW PTHREAD_CANCEL(bestFit); close_pipe_handler(); return(0); #endif }