int main(int argc, char *argv[]) { struct rooted_tree *tree; struct parameters params; params = get_params(argc, argv); while ((tree = parse_tree()) != NULL) { process_tree(tree, params); destroy_tree(tree, DONT_FREE_NODE_DATA); } if (EXACT == params.mode) destroy_llist(params.labels); else { /* This does not free 'params.regexp' itself, only memory pointed to by 'params.regexp' * members and allocated by regcomp().*/ regfree(params.regexp); /* Therefore: */ free(params.regexp); } return 0; }
NOEXPORT int service_install() { SC_HANDLE scm, service; TCHAR stunnel_exe_path[MAX_PATH]; LPTSTR service_path; TCHAR descr_str[DESCR_LEN]; SERVICE_DESCRIPTION descr; scm=OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE); if(!scm) { error_box(TEXT("OpenSCManager")); return 1; } GetModuleFileName(0, stunnel_exe_path, MAX_PATH); service_path=str_tprintf(TEXT("\"%s\" -service %s"), stunnel_exe_path, get_params()); service=CreateService(scm, SERVICE_NAME, SERVICE_DISPLAY_NAME, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, service_path, NULL, NULL, TEXT("TCPIP\0"), NULL, NULL); if(!service) { error_box(TEXT("CreateService")); str_free(service_path); CloseServiceHandle(scm); return 1; } str_free(service_path); if(LoadString(ghInst, IDS_SERVICE_DESC, descr_str, DESCR_LEN)) { descr.lpDescription=descr_str; ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &descr); } message_box(TEXT("Service installed"), MB_ICONINFORMATION); CloseServiceHandle(service); CloseServiceHandle(scm); return 0; }
int mouse_hook(int button, int x, int y, t_disp *d) { t_param *par; par = get_params(); (void)x; (void)y; if (button == 2) { par->proj += 1; redraw_image(d); } if (button == 4 && par->zoom < 100) { par->zoom += 1; redraw_image(d); } if (button == 5 && par->zoom > 1) { par->zoom -= 1; redraw_image(d); } return (0); }
/*------------------------------------------------------ Proceso principal -----------------------------------------------------*/ int main(int argc, char **argv) { global_config config; pthread_t* threads; if (get_params(argv + 1, argc - 1, &config) != SUCCESS) { printf("Error en los argumentos recibidos.\nEjemplo de uso:"); printf("%s cantidadDeThreds fileSizeInKbytes directory filePrefix\n", argv[0]); return EXIT_FAILURE; } print_a_global_header(config); threads = threads_create(config); threads_get_and_print_results(threads, config.threads_amount, config.location, config.files_prefix); threads_destroy(threads, 0); destroy_params(config); return EXIT_SUCCESS; }
void readgraph(FILE* fp){ int i,j; int length = 0; if (!fscanf(fp, "%d\n", &length)) { printf("ERROR: Corrupted preamble.\n"); exit(10); } if(length >= MAX_PREAMBLE) { printf("ERROR: Too long preamble.\n"); exit(10); } fread(Preamble, 1, length, fp); Preamble[length] = '\0'; if (!get_params()) { printf("ERROR: Corrupted preamble.\n"); exit(10); } if (Nr_vert >NMAX) { printf("Too many vertices! Recompile with NMAX > %d\n", Nr_vert); exit(0); } for ( i = 0 ; i < Nr_vert && fread(Bitmap[i], 1, (int)((i + 8)/8), fp) ; i++ ); fclose(fp); N = Nr_vert; for (i = 0; i < N; i++) for (j = 0; j < N; j++) if (get_edge(i, j)){ bitmap[(j+1)/CHARBITS][i+1] |= (1 << ((j+1) % CHARBITS)); } }
static ngx_int_t ngx_restfull_redis_handler(ngx_http_request_t *r) { //TODO: deal with allocation problem - return 500 ngx_chain_t out; out.buf = create_response_buffer(r);; out.next = NULL; dd("command => %s", command(r)); char* redis_command = command(r); define_content_type(r, "application/json; charset=utf-8"); redisContext *c = redisConnect("127.0.0.1", 6379); if (c->err) { dd("Error: %s\n", c->errstr); write_to_buffer(out.buf, (u_char*) "Can't connect to redis", strlen("Can't connect to redis")); } Hash* params = get_params(r); redisReply *reply; if(!strcmp(redis_command, "get")) { reply = redisCommand(c,"GET %s", params->get(params, "key")); dd("Redis reply status: %d", reply->type); if(key_not_found(reply)) { not_found(r, out.buf, (u_char*)"not found"); return ngx_http_output_filter(r, &out); } dd("reply: %s", reply->str); u_char * result = copy(r->pool, reply->str, reply->len); write_to_buffer(out.buf, result, reply->len); write_header(r, NGX_HTTP_OK, reply->len); } else if (!strcmp(redis_command, "set")) { reply = redisCommand(c,"SET %s %s", params->get(params, "key"), params->get(params, "value")); dd("Redis reply status: %d", reply->type); if(key_not_found(reply)) { not_found(r, out.buf, (u_char*)"not found"); return ngx_http_output_filter(r, &out); } dd("Reply set %s -- %d", reply->str, reply->len); write_to_buffer(out.buf, (u_char*) reply->str, reply->len); write_header(r, NGX_HTTP_OK, reply->len); } else if(!strcmp(redis_command, "incr")) { reply = redisCommand(c,"INCR %s", params->get(params, "key")); dd("Redis reply status: %d", reply->type); int len = number_of_digits(reply->integer); dd("Reply INCR -- %d - len %d", (int)reply->integer, len); u_char* result = ngx_pcalloc(r->pool, sizeof(char)*len); sprintf((char*)result,"%d",(int)reply->integer); write_to_buffer(out.buf, result, len); write_header(r, NGX_HTTP_OK, len); } freeReplyObject(reply); redisFree(c); ngx_free(params); return ngx_http_output_filter(r, &out); }
int main(int argc,char *argv[]) { PARAMS params; SSDATA *data = NULL; long int pid; int force=0,rejects=0,usage=0,c; /* Disable stdout buffering */ setbuf(stdout,(char *) NULL); /* Check arguments */ while ((c = getopt(argc,argv,"fr")) != EOF) switch (c) { case 'f': force = 1; break; case 'r': rejects = 1; break; default: usage = 1; } if (usage || optind < argc) { (void) fprintf(stderr,"Usage: %s [ -f ] [ -r ]\n",argv[0]); exit(1); } /* Get model parameters */ get_params(¶ms); if (!force && !rejects) { FILE *fp = fopen(OUTPUT_FILE,"r"); if (fp) { (void) fprintf(stderr,"%s NOT OVERWRITTEN.\n",OUTPUT_FILE); (void) fclose(fp); return 1; } } /* Generate initial conditions */ pid = getpid(); (void) printf("Random number seed = %li\n",pid); srand(pid); if (rejects) { assert(0); /* not supported currently: do it the N^2 way for now */ fix_rejects(¶ms); return 0; } if (!(data = (SSDATA *) malloc(params.N*sizeof(SSDATA)))) { (void) fprintf(stderr,"Unable to allocate data memory\n"); return 1; } generate(¶ms,data); /* Save data */ output_data(¶ms,data); /* All done */ free((void *) data); return 0; }
/*--------------------------------------------------------*/ int main(int argc, char *argv[]) { char *parfname, *instrname, *maskname, *reffname, *imgfname, **inpfname, **outfname, **kerfname; unsigned short *mask0, *mask1, *flag0, *flag1; int *indx, nsec_x, nsec_y, isec_x, isec_y, x_off, y_off, mode, deg[MAX_NCOMP], i, k, nclip, npix, nim, ntab, nkeep; long int imglen, buflen, veclen, intlen, matlen, usblen, lomlen, lovlen, tablen, domlen, srtlen, *headlen, mheadlen, rheadlen; float *im, *imref, *imdif, sig[MAX_NCOMP], *sort_buf; double **vecs, **mat, *vec, **tab00, **wxy, *ker_norm, chi2_n, good_area, total_area, parity; DOM_TABS *domp; PARAMS par; /**************************************************************************/ imref = imdif = NULL; mask0 = mask1 = NULL; flag0 = flag1 = NULL; indx = NULL; vec = NULL; vecs = mat = NULL; tab00 = wxy = NULL; sort_buf = NULL; good_area = 0.0; domp = 0; /*** argument handling ***/ if (argc != 6) usage(); parfname = argv[1]; instrname= argv[2]; maskname = argv[3]; reffname = argv[4]; imgfname = argv[5]; /**************************************************************************/ /*** get parameters ***/ /**************************************************************************/ par.deg = deg; par.sig = sig; get_params(parfname, instrname, &par); if (par.verbose > 3) { printf("parfname: %s\n", parfname); printf("instrname: %s\n", instrname); printf("maskname: %s\n", maskname); printf("reffname: %s\n", reffname); printf("imgfname: %s\n", imgfname); printf("--------------\n"); } /*** get the list of input, output and kernel files ***/ if (par.verbose > 2) printf("Reading '%s'\n", imgfname); nim=read_list(par, imgfname, &inpfname, &outfname, &kerfname); if (par.verbose > 2) printf("%d file-names read read\n", nim); for (i=1; i<par.ncomp; i++) { par.deg[i] = par.deg[i-1] + par.deg_inc; par.sig[i] = par.sig[i-1] * par.sig_inc; } par.nx += 2*par.kerhw; par.ny += 2*par.kerhw; par.sdeg = par.wdeg; if (par.bdeg > par.wdeg) par.sdeg = par.bdeg; par.nwxy = (par.wdeg+1)*(par.wdeg+2)/2; par.nspat = (par.sdeg+1)*(par.sdeg+2)/2; par.nbkg = (par.bdeg+1)*(par.bdeg+2)/2; par.nvecs = par.nbkg; for (i=0; i<par.ncomp; i++) par.nvecs += (par.deg[i]+1)*(par.deg[i]+2)/2; par.ntot = par.nvecs + (par.nvecs - par.nbkg - 1)*(par.nwxy - 1); par.ndom = par.ndom_x*par.ndom_y; ntab = par.nvecs-par.nbkg+par.nspat; if (par.verbose) printf("\t %d image(s) to process\n\n", nim); /**************************************************************************/ /*** get memory ***/ /**************************************************************************/ imglen = par.nx*par.ny*sizeof(float); buflen = par.nx*par.ny*sizeof(double); matlen = par.ntot*sizeof(double *); veclen = par.ntot*sizeof(double); usblen = par.nx*par.ny*sizeof(unsigned short); tablen = ntab*sizeof(double *); lomlen = par.nvecs*sizeof(double *); lovlen = par.nvecs*sizeof(double); domlen = par.ndom*sizeof(DOM_TABS); srtlen = par.ndom*sizeof(float); intlen = par.ndom*sizeof(int); if (par.ntot > par.ndom) intlen = par.ntot*sizeof(int); if (!(im = (float *)malloc(imglen))) errmess("malloc(im)"); if (!(imref = (float *)malloc(imglen))) errmess("malloc(imref)"); if (!(imdif = (float *)malloc(imglen))) errmess("malloc(imdif)"); if (!(mat = (double **)malloc(matlen))) errmess("malloc(mat)"); if (!(tab00 = (double **)malloc(tablen))) errmess("malloc(tab00)"); if (!(vecs = (double **)malloc(tablen))) errmess("malloc(vecs)"); if (!(wxy = (double **)malloc(tablen))) errmess("malloc(wxy)"); if (!(domp = (DOM_TABS *)malloc(domlen))) errmess("malloc(DOM_TABS)"); if (!(sort_buf = (float *)malloc(srtlen))) errmess("malloc(sort_buf)"); for (i=0; i<ntab; i++) if (!(tab00[i] = (double *)malloc(buflen))) errmess("malloc(tab00[i])"); for (k=0; k<par.ndom; k++) { if (!(domp[k].mat0 = (double **)malloc(lomlen))) errmess("malloc(domp[k].mat0)"); if (!(domp[k].mat1 = (double **)malloc(lomlen))) errmess("malloc(domp[k].mat1)"); if (!(domp[k].mat = (double **)malloc(lomlen))) errmess("malloc(domp[k].mat)"); if (!(domp[k].vec0 = (double *)malloc(lovlen))) errmess("malloc(domp[k].vec0)"); if (!(domp[k].vec = (double *)malloc(lovlen))) errmess("malloc(domp[k].vec)"); for (i=0; i<par.nvecs; i++) { if (!(domp[k].mat0[i] = (double *)malloc(lovlen))) errmess("malloc(domp[k].mat0[i])"); if (!(domp[k].mat1[i] = (double *)malloc(lovlen))) errmess("malloc(domp[k].mat1[i])"); if (!(domp[k].mat[i] = (double *)malloc(lovlen))) errmess("malloc(domp[k].mat[i])"); } } /* mat is indexed from 1 to n for use with numerical recipes ! */ for (i=0; i<par.ntot; i++) { if (!(mat[i] = (double *)malloc(veclen))) errmess("malloc(mat[i])"); mat[i]--; } mat--; if (!(vec = (double *)malloc(veclen))) errmess("malloc(vec)"); if (!(indx = (int *)malloc(intlen))) errmess("malloc(indx)"); if (!(mask0 = (unsigned short *)malloc(usblen))) errmess("malloc(mask0)"); if (!(mask1 = (unsigned short *)malloc(usblen))) errmess("malloc(mask1)"); if (!(flag0 = (unsigned short *)malloc(usblen))) errmess("malloc(flag0)"); if (!(flag1 = (unsigned short *)malloc(usblen))) errmess("malloc(flag1)"); if (!(headlen=(long *)calloc(nim, sizeof(long)))) errmess("calloc(headlen)"); if (!(ker_norm=(double *)calloc(nim, sizeof(double)))) errmess("calloc(ker_norm)"); /**************************************************************************/ /**************************************************************************/ /* get information about header sizes */ mheadlen=get_headlen(maskname); rheadlen=get_headlen(reffname); init_difimages(inpfname, outfname, headlen, nim, par); /**************************************************************************/ if (par.verbose > 4) { printf("par.nx0= %d par.ny0 = %d\n", par.nx0, par.ny0); printf("par.kerhw= %d\n", par.kerhw); printf("par.nx= %d par.ny = %d\n", par.nx, par.ny); } nsec_x = (par.nx0 - 2*par.kerhw)/(par.nx - 2*par.kerhw); nsec_y = (par.ny0 - 2*par.kerhw)/(par.ny - 2*par.kerhw); /**************************************************************************/ /*** main loop over sections of each image ***/ /**************************************************************************/ if (par.verbose > 4) printf("main loop over sections: nsec_x= %d nsec_y= %d\n", nsec_x, nsec_y); for (isec_x=0; isec_x<nsec_x; isec_x++) { for (isec_y=0; isec_y<nsec_y; isec_y++) { y_off = isec_y*(par.ny - 2*par.kerhw); x_off = isec_x*(par.nx - 2*par.kerhw); mode = (int)( isec_x || isec_y ); if (par.verbose > 4) printf("isec_x= %d isec_y= %d mode= %d\n", isec_x, isec_y, mode); read_sector(maskname, mheadlen, par.nx0, par.ny0, x_off, y_off, (char *)mask0, sizeof(unsigned short), par.nx, par.ny); read_sector(reffname, rheadlen, par.nx0, par.ny0, x_off, y_off, (char *)imref, sizeof(float), par.nx, par.ny); make_vectors(imref, tab00, vecs, wxy, par); mask_badpix(imref, mask0, flag0, 0, par); get_domains(imref, mask0, domp, par, &par.ndom); make_domains(imref, mask0, vecs, domp, par); total_area = (2*par.domhw + 1); total_area *= total_area*par.ndom; /**********************************************/ /*** loop over images for a given section ***/ /**********************************************/ for (i=0; i<nim; i++) { if (par.verbose >= VERB_MED) printf("\nSection [%d,%d] of image %d : %s\n", isec_x+1, isec_y+1, i+1, inpfname[i]); read_sector(inpfname[i], headlen[i], par.nx0, par.ny0, x_off, y_off, (char *)im, sizeof(float), par.nx, par.ny); mask_badpix(im, mask1, flag1, 1, par); npix = clean_domains(im, imref, mask0, mask1, vecs, domp, par); /*** sigma clipping ***/ chi2_n = BIG_FLOAT; if (par.verbose >= VERB_MED) { printf("\nLocal sigma clipping of domains:\n"); printf(" iteration chi2/dof N(clip) N(fit)\n"); } for (k=0; k<=par.n_iter+1; k++) { good_area = npix/total_area; if (good_area < par.min_area) break; clone_domains(domp, par.ndom, par.nvecs); /**************************/ if (k > 0) { nclip = local_clip(im, imref, mask1, vecs, wxy, vec, domp, par, &chi2_n, &npix); if (par.verbose >= VERB_MED) printf("%6d\t%14.4f\t%9d\t%7d\n", k-1, par.gain*chi2_n, nclip, npix); } /**************************/ expand_matrix(mat, vec, wxy, domp, par); ludcmp(mat, par.ntot, indx-1, &parity); lubksb(mat, par.ntot, indx-1, vec-1); } if (par.verbose >= VERB_MED) { printf("\nSigma clipping of domain distribution:\n"); printf("iteration median chi2/dof sigma N(good)\n"); } nkeep = par.ndom; for (k=1; k<=par.n_iter_dom && nkeep>=par.min_nkeep; k++) nkeep = clip_domains(domp, sort_buf, indx, k, &chi2_n, par); /*** sigma clipping ends ***/ chi2_n *= par.gain; /*** final solution ***/ if (good_area < par.min_area) { printf("\nFailed for section [%d,%d] of image %d : %s\n", isec_x+1, isec_y+1, i+1, inpfname[i]); printf("*** [ good_area= %f < %f ] ***\n", good_area, par.min_area); } else if (chi2_n > par.max_chi2) { printf("\nFailed for section [%d,%d] of image %d : %s\n", isec_x+1, isec_y+1, i+1, inpfname[i]); printf("*** [ chi2_n= %f > %f ] ***\n", chi2_n, par.max_chi2); } else if (nkeep < par.min_nkeep) { printf("\nFailed for section [%d,%d] of image %d : %s\n", isec_x+1, isec_y+1, i+1, inpfname[i]); printf("*** [ nkeep= %d < %d ] ***\n", nkeep, par.min_nkeep); } else { expand_matrix(mat, vec, wxy, domp, par); ludcmp(mat, par.ntot, indx-1, &parity); lubksb(mat, par.ntot, indx-1, vec-1); spatial_convolve(im, imdif, vecs, wxy, vec, par); /*** output ***/ ker_norm[i] = vec[par.nbkg]; apply_norm(imdif, flag0, flag1, ker_norm[i], par.nx, par.ny, par.bad_value); write_sector(outfname[i], headlen[i], par.nx0, par.ny0, x_off, y_off, (char *)imdif, sizeof(float), par.nx, par.ny, par.kerhw); } if (par.verbose) write_kernel(kerfname[i], vec, nsec_x, nsec_y, mode, par, &chi2_n); } /**********************************************/ /*** loop over images ends ***/ /**********************************************/ } } /**********************************************/ /*** loop over sections ends ***/ /**********************************************/ if (par.verbose >= VERB_HIGH) { printf("\nKernel norms:\n\n"); for (i=0; i<nim; i++) printf("%s \t %8.5f\n", kerfname[i], ker_norm[i]); printf("\n"); } for (i=0; i<nim; i++) { free(inpfname[i]); free(outfname[i]); free(kerfname[i]); } free(inpfname); free(outfname); free(kerfname); free(headlen); free(ker_norm); return(0); }
int main( int argc, char **argv ){ /* MPI Initialization */ int nprocs, rank; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* CL input for total number of stars in each mock */ if (argc != 2){ fprintf( stderr, "Error. Usage: %s num_stars\n", argv[0]); exit(EXIT_FAILURE); } /* total number of stars in temp galaxy */ unsigned long int N_stars; sscanf(argv[1], "%lu", &N_stars); if(rank==0) fprintf(stderr, "%lu stars per temporary galaxy.\n", N_stars); /* have each process only make some stars */ N_stars /= nprocs; if(rank==0) fprintf(stderr, "%d processes each responsible for %lu stars.\n", nprocs, N_stars); /* different variables used in main */ POINTING *plist; /* a pointing structure */ int N_plist; /* number of l.o.s. */ int loop_flag; /* set = 0 when file creation complete */ int pointings_in_need; /* a progress checker */ PARAMS params; /* parameters for mock creation */ time_t t; /* initialization of random seed */ int N_mock; /* # of stars in current mock l.o.s. */ int N_mock_temp; int N_mock_proc; int N_data; /* desired # of stars in current l.o.s. */ int i; /* for loop index */ int loop_counter; /* a progress checker */ /* have each proc separately load info for different pointings */ int current_rank = 0; while ( current_rank < nprocs ){ if (current_rank == rank) load_pointing_list(&N_plist, &plist, rank); MPI_Barrier(MPI_COMM_WORLD); current_rank++; } /* get info for mock */ /* change this to CL input eventually */ get_params(¶ms, N_stars, rank); /* Allocate arrays for galactic coordinates */ STAR * thin = malloc(params.N_thin * sizeof(STAR)); STAR * thick = malloc(params.N_thick * sizeof(STAR)); /* initialize random seed -- make different for each mock */ srand((unsigned) time(&t) + (1+rank)); /* Initialize for while loop */ loop_flag = 0; loop_counter = 0; /* create temp mocks until all l.o.s. are filled */ while(loop_flag==0){ /* re-initialize at each step */ pointings_in_need = 0; loop_flag = 1; /* Make thin and thick disks */ generate_stars(thin, ¶ms, 0); generate_stars(thick, ¶ms, 1); /* Separate stars into appropriate l.o.s. */ separate_sample(plist, thin, N_plist, params.N_thin, rank); separate_sample(plist, thick, N_plist, params.N_thick, rank); /* Check all l.o.s. to see if we have enough stars */ for( i=0; i<N_plist; i++ ){ /* set total stars for this temp gxy = 0 */ N_mock_temp = 0; /* current pointings stars/proc */ N_mock_proc = plist[i].N_mock_proc; /* Sum stars across all processes to get pointing's total stars for this temp gxy */ MPI_Allreduce(&N_mock_proc, &N_mock_temp, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); /* Add temp galaxy's stars to total */ plist[i].N_mock += N_mock_temp; N_mock = plist[i].N_mock; N_data = plist[i].N_data; if(N_mock<N_data){ /* indicate that we need more stars */ loop_flag = 0; plist[i].flag = 0; pointings_in_need += 1; } else{ /* we don't need more stars for this l.o.s. */ plist[i].flag = 1; } } /* update progress and output results to user */ loop_counter +=1; if(rank==0){ fprintf(stderr, "We've run the loop %d times.\n", loop_counter); if (pointings_in_need != 0){ fprintf(stderr, "%d pointings need more stars.\n", pointings_in_need); fprintf(stderr, "Making more stars. \n"); } else fprintf(stderr, "All pointings have an adequate number of stars. \n"); } } /* Deallocate arrays */ free(thin); free(thick); free(plist); if(rank==0) fprintf(stderr, "Files Written. Arrays deallocated.\n"); MPI_Finalize(); return 0; }
int main (int argc, char *argv[]) { Zoltan_DD_Directory *dd; ZTIMER *zt; int myproc; /* MPI rank, my processor's MPI ID */ int nproc; /* MPI size, number of processors */ ZOLTAN_ID_PTR glist = NULL; /* list of GIDs */ ZOLTAN_ID_PTR llist = NULL; /* list of LIDs */ ZOLTAN_ID_PTR ulist = NULL; /* list of user data of type ZOLTAN_ID_TYPE */ int *plist = NULL; /* list of partitions */ int *olist = NULL; /* list of owners */ Param param ; /* program's adjustable parameters */ char *store = NULL; /* non directory storage of test data */ Data *data = NULL; /* pointer into store */ /* these are all temporary variables */ int new_owner; int count; int i; char *p; int err; int errcount; int loop; char str[100]; /* for building output messages */ static int timer[7] = {-1,-1,-1,-1,-1,-1,-1}; char *yo = "DD_Main"; /* initialize MPI communications, ignore errors */ MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &myproc); MPI_Comm_size (MPI_COMM_WORLD, &nproc); get_params (¶m); /* read input parameters */ zt = Zoltan_Timer_Create(1); MACRO_TIMER_START(5, "Total time", 0); MACRO_TIMER_START(0, "DD_Create time", 0); err = Zoltan_DD_Create (&dd, MPI_COMM_WORLD, param.glen, param.llen, param.ulen, param.tlen, param.debug_level); if (err != ZOLTAN_OK) ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Create"); MACRO_TIMER_STOP(0); param.slen = sizeof (Data) + sizeof(ZOLTAN_ID_TYPE) * (param.glen + param.llen + param.ulen); param.slen = Zoltan_Align(param.slen); store = (char*) ZOLTAN_MALLOC (param.count * param.slen); /* allocate storage for various lists */ glist = (ZOLTAN_ID_PTR) ZOLTAN_MALLOC(sizeof(ZOLTAN_ID_TYPE) * param.count * param.glen); plist = (int*) ZOLTAN_MALLOC (sizeof(int) * param.count); olist = (int*) ZOLTAN_MALLOC (sizeof(int) * param.count); if (param.llen) llist = (ZOLTAN_ID_PTR) ZOLTAN_MALLOC (sizeof (ZOLTAN_ID_TYPE) * param.count * param.llen); if (param.ulen) ulist = (ZOLTAN_ID_PTR) ZOLTAN_MALLOC (sizeof (ZOLTAN_ID_TYPE) * param.count * param.ulen) ; if (store == NULL || glist == NULL || (param.llen != 0 && llist == NULL) || (param.ulen != 0 && ulist == NULL) || plist == NULL || olist == NULL) { ZOLTAN_PRINT_ERROR (myproc, yo, "Unable to malloc storage lists"); return ZOLTAN_MEMERR; } initialize_data (¶m, store, nproc); /* create & update directory with myproc's initial simulated GIDs */ count = 0; for (p = store; p < store + param.count * param.slen; p += param.slen) if (((Data *)p)->new_owner == myproc) { ZOLTAN_SET_ID (param.glen, glist + count * param.glen, ((Data*)p)->id); if (param.llen) ZOLTAN_SET_ID (param.llen, llist + count * param.llen, ((Data *)p)->id + param.glen); if (param.ulen) ZOLTAN_SET_ID (param.ulen, ulist + count * param.ulen, ((Data *)p)->id + (param.glen + param.llen)); plist [count] = ((Data *)p)->partition; ++count; } MACRO_TIMER_START (1, "DD_Update timer", 0); err = Zoltan_DD_Update (dd, glist, llist, ulist, plist, count); if (err != ZOLTAN_OK) ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Update"); MACRO_TIMER_STOP(1); i = 0; for (p = store; p < store + param.count * param.slen; p += param.slen) { ZOLTAN_SET_ID (param.glen, glist + i * param.glen, ((Data *)p)->id); ++i; } MACRO_TIMER_START(2, "DD_Find timer", 0); err = Zoltan_DD_Find (dd, glist, llist, ulist, plist, param.count, olist); if (err != ZOLTAN_OK) ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Find"); MACRO_TIMER_STOP(2); errcount = 0; for (i = 0; i < param.count; i++) if (olist[i] != ((Data *) (store + i * param.slen))->new_owner) ++errcount; if (errcount) sprintf (str, "FIRST TEST FAILED, errcount is %d", errcount); else sprintf (str, "FIRST TEST SUCCESSFUL"); ZOLTAN_PRINT_INFO (myproc, yo, str); /* repeatedly simulate moving "dots" around the system */ for (loop = 0; loop < param.nloops; loop++) { for (p = store; p < store + param.count * param.slen; p += param.slen) ((Data*) p)->old_owner = ((Data*) p)->new_owner; /* randomly exchange some dots and randomly reassign others */ for (i = 0; i < (param.pmove * param.count)/100; i++) { Data *d1, *d2; d1 = (Data*) (store + param.slen * (rand() % param.count)); d2 = (Data*) (store + param.slen * (rand() % param.count)); new_owner = d1->new_owner; d1->new_owner = d2->new_owner; d2->new_owner = new_owner; } for (i = 0; i < (param.count * param.pscatter)/100; i++) ((Data*) (store + param.slen *(rand() % param.count)))->new_owner = rand() % nproc; /* determine which new GIDs myproc gained, and update directory */ count = 0; for (p = store; p < store + param.count * param.slen; p += param.slen) if (((Data*)p)->new_owner == myproc) { ((Data*)p)->id[param.glen] = count; /* set LID */ ZOLTAN_SET_ID (param.glen, glist + count * param.glen, ((Data *)p)->id); if (param.llen) ZOLTAN_SET_ID (param.llen, llist + count * param.llen, ((Data*)p)->id + param.glen); if (param.ulen) ZOLTAN_SET_ID (param.ulen, ulist + count * param.ulen, ((Data*)p)->id + (param.glen + param.llen)); plist [count] = ((Data *)p)->partition; ++count; } MACRO_TIMER_START(1, "DD_Update", 0); err = Zoltan_DD_Update (dd, glist, llist, ulist, plist, count); if (err != ZOLTAN_OK) ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Update"); MACRO_TIMER_STOP(1); /* use directory to "find" GIDs */ i = 0; for (p = store; p < store + param.count * param.slen; p += param.slen) { ZOLTAN_SET_ID (param.glen, glist + i * param.glen, ((Data *)p)->id); ++i; } MACRO_TIMER_START(2, "DD_Find timer", 0); if (loop % 5 == 0) err = Zoltan_DD_Find(dd,glist,NULL,ulist,plist,param.count,olist); else if (loop % 7 == 0) err = Zoltan_DD_Find(dd,glist,llist,NULL,plist,param.count,olist); else if (loop % 9 == 0) err = Zoltan_DD_Find(dd,glist,llist,ulist,NULL,param.count,olist); else if (loop % 2 == 0) err = Zoltan_DD_Find(dd,glist,llist,ulist,plist,param.count,NULL); else err = Zoltan_DD_Find(dd,glist,llist,ulist,plist,param.count,olist); if (err != ZOLTAN_OK) ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Find"); MACRO_TIMER_STOP(2); if (loop % 2) { errcount = 0 ; for (i = 0; i < param.count; i++) if (olist[i] != ((Data *)(store + i * param.slen))->new_owner) ++errcount; if (errcount) sprintf (str,"LOOP %d TEST FAILED, errcount is %d",loop,errcount); else sprintf (str, "LOOP %d TEST SUCCESSFUL", loop); ZOLTAN_PRINT_INFO (myproc, yo, str) ; } else { sprintf (str, "LOOP %d Completed", loop); ZOLTAN_PRINT_INFO (myproc, yo, str); } /* randomly remove a percentage of GIDs from the directory */ count = 0; for (i = 0; i < (param.count * param.pdelete)/100; i++) { data = (Data*) (store + param.slen * (rand() % param.count)); if (data->new_owner == myproc) { ZOLTAN_SET_ID (param.glen, glist + count * param.glen, data->id); ++count; } data->new_owner = NO_PROC; } MACRO_TIMER_START(3, "DD_Remove timer", 0); err = Zoltan_DD_Remove (dd, glist, count); MACRO_TIMER_STOP(3); if (err != ZOLTAN_OK) ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Remove"); /* update directory (put directory entries back in) */ for (p = store; p < store + param.count * param.slen; p += param.slen) if (((Data*)p)->new_owner == NO_PROC) ((Data*)p)->new_owner = loop % nproc; /* place in new location */ count = 0; for (p = store; p < store + param.count * param.slen; p += param.slen) if (((Data*)p)->new_owner == myproc) { ZOLTAN_SET_ID(param.glen,glist+count*param.glen,((Data*)p)->id); if (param.llen) ZOLTAN_SET_ID (param.llen, llist + count * param.llen, ((Data*)p)->id + param.glen); if (param.ulen) ZOLTAN_SET_ID(param.ulen, ulist + count * param.ulen, ((Data *)p)->id + (param.glen + param.llen)); plist [count] = ((Data*)p)->partition; ++count; } MACRO_TIMER_START(1, "DD_Update timer", 0); err = Zoltan_DD_Update (dd, glist, NULL, NULL, NULL, count); if (err != ZOLTAN_OK) ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Update"); MACRO_TIMER_STOP(1); } /* now Find directory info for GIDs myproc now owns and validate */ count = 0; for (i = 0; i < param.count; i++) { data = (Data *) (store + i * param.slen); if (data->new_owner == myproc) { ZOLTAN_SET_ID (param.glen, glist + count * param.glen, data->id); ++count; } } MACRO_TIMER_START(2, "DD_Find", 0); err = Zoltan_DD_Find (dd, glist, NULL, NULL, NULL, count, olist); if (err != ZOLTAN_OK) ZOLTAN_PRINT_ERROR (myproc, yo, "Failed return from DD Find"); MACRO_TIMER_STOP(2); errcount = 0; for (i = 0; i < count; i++) if (olist[i] != myproc) ++errcount; if (errcount) { sprintf (str, "errcount is %d", errcount); ZOLTAN_PRINT_ERROR (myproc, yo, str); } else ZOLTAN_PRINT_INFO (myproc, yo, "TEST SUCCESSFUL"); Zoltan_DD_Stats (dd); /* done, now free memory, stop MPI & directory, return */ ZOLTAN_FREE (&store); ZOLTAN_FREE (&glist); ZOLTAN_FREE (&plist); ZOLTAN_FREE (&olist); if (param.llen) ZOLTAN_FREE (&llist); if (param.ulen) ZOLTAN_FREE (&ulist); ZOLTAN_PRINT_INFO (myproc, yo, "Completing program"); MACRO_TIMER_START(4, "DD_Destroy", 0); Zoltan_DD_Destroy (&dd); MACRO_TIMER_STOP(4); MACRO_TIMER_STOP(5); Zoltan_Timer_PrintAll(zt, 0, MPI_COMM_WORLD, stderr); MPI_Finalize (); return ZOLTAN_OK; }
void shell_process(PROCESS self, PARAM param) { clear_window(&shell_wnd); //print_all_processes(&shell_wnd); //testStringCompare(); char inBuf[128] = ""; char param1[128] = "\0"; char param2[128] = "\0"; char param3[128] = "\0"; int bufSize = sizeof(inBuf)/sizeof(char); int bufCurs = 0; int i; char ch; Keyb_Message msg; // Command int (*func)(param1, param2); while (1) { // reset vars after each command is processed ch = 0; bufCurs = 0; for(i = 0; i < 128; i++) { inBuf[i] = 0; param1[i] = 0; param2[i] = 0; param3[i] = 0; } // output command prompt wprintf(&shell_wnd, "SamOS >>> "); //read command from keyboard, terminate upon reading newline while(ch != 13) { // check for buffer overflow if(bufCurs > 126) { wprintf(&shell_wnd, "\nTrying to overflow the buffer? Try again, Bub\n"); break; } msg.key_buffer = &ch; send(keyb_port, &msg); // cover case of backspace if(ch == '\b') { // do nothing if buffer is empty if(bufCurs == 0) { continue; } else { inBuf[bufCurs] = 0; bufCurs--; } } else if(ch != 13) { // commit entered character to buffer, increment cursor inBuf[bufCurs] = ch; bufCurs++; } // output entered character to console output_char(&shell_wnd, ch); } // input buffer debug //wprintf(&shell_wnd,inBuf); get_params(inBuf,param1,param2,param3); executeCommand(param1,param2,param3); } }
void GLEPolish::internalPolish(GLEPcode& pcode, int *rtype) throw(ParserError) { GLESub* sub; string uc_token; int idx, ret, np, *plist, term_bracket = false; int curpri = 0; int nstk = 0, stk[50], stkp[50]; /* stack for operators */ int unary = 1; /* binary or unary operation expected */ bool isa_string = false; bool not_string = false; if (*rtype==1) not_string = true; if (*rtype>0) term_bracket = true; pcode.addInt(PCODE_EXPR); /* Expression follows */ int savelen = pcode.size(); /* Used to set acutal length at end */ pcode.addInt(0); /* Length of expression */ while (true) { string token = m_tokens.try_next_token(); int token_col = m_tokens.token_pos_col(); int token_len = token.length(); char first_char = token_len > 0 ? token[0] : ' '; // cout << "Token: '" << token << "'" << endl; // end of stream, or found ',' or ')' if (token_len == 0 || (token_len == 1 && (first_char == ',' || (first_char == ')' && curpri == 0) || (first_char == ']' && curpri == 0)))) { if (token_len != 0) { m_tokens.pushback_token(); } *rtype = 0; dbg gprint("Found END OF EXPRESSION \n"); if (curpri != 0) { throw error("unexpected end of expression, missing closing ')' or ']'"); } /* Pop everything off the stack */ for (int i = nstk; i > 0; i--) { dbg gprint("Adding left over operators I = %d op=%d \n",i,stk[i]); pcode.addInt(stk[i]); } if (unary == 1) { throw error("constant, function, or unary operator expected"); } pcode.setInt(savelen, pcode.size() - savelen - 1); #ifdef DEBUG_POLISH pcode.show(savelen); #endif return; } dbg gprint("First word token via (1=unary %d) cts {%s}\n ", unary, token.c_str()); switch (unary) { case 1: /* a unary operator, or function, or number or variable */ if (is_float(token)) { dbg gprint("Found number {%s}\n",token.c_str()); double value = atof(token.c_str()); pcode.addDouble(value); unary = 2; break; } str_to_uppercase(token, uc_token); /* NOT a number, is it a built in function? */ find_un((char*)uc_token.c_str(), &idx, &ret, &np, &plist); /* 1,2 = +,- */ if (idx > 3 && m_tokens.is_next_token("(")) { // // it is a built in function // dbg gprint("Found built in function \n"); get_params(pcode, np, plist, uc_token); pcode.addFunction(idx + FN_BUILTIN_MAGIC); unary = 2; break; } else if (idx > 0 && idx <= 3) { stack_fn(idx); unary = 1; break; } /* Is it a user-defined function, identical code too above. */ sub = sub_find((char*)uc_token.c_str()); if (sub != NULL && m_tokens.is_next_token("(")) { // // it is a user defined function // // printf("User cts=%s idx=%d ret=%d np=%d plist=%d\n",cts,idx,ret,np,plist); dbg gprint("Found user function \n"); get_params(pcode, sub->getNbParam(), sub->getParamTypes(), uc_token); pcode.addFunction(sub->getIndex()+LOCAL_START_INDEX); unary = 2; break; } /* Is it a 'known' variable */ int v; var_find((char*)uc_token.c_str(), &v, &ret); if (v >= 0) { // cout << "found var: '" << uc_token << "' -> " << v << endl; if (ret == 2) pcode.addStrVar(v); else pcode.addVar(v); unary = 2; if (m_vars != NULL && m_vars->try_get(uc_token) == -1) { /* Add it to list of vars */ m_vars->add_item(uc_token, v); } break; } /* Is it a string */ if (first_char == '"' || first_char == '\'') { dbg gprint("Found string \n"); string str_no_quote = token; str_remove_quote(str_no_quote); pcode.addString(str_no_quote); unary = 2; break; } if ((first_char == 'd' || first_char == 'D') && token_len == 1 && m_tokens.is_next_token("[")) { get_array_index(pcode); pcode.addFunction(FN_DI + FN_BUILTIN_MAGIC); unary = 2; break; } if (first_char == '(' && token_len == 1) { curpri = curpri + 100; break; } if ((first_char == ')' || first_char == ')') && token_len == 1) { throw error("constant, function, or unary operator expected"); } if (m_tokens.is_next_token("(")) { throw error(token_col, string("call to undefined function '"+token+"'")); } /* must be unquoted string, unless a binary operator was found, in which case it is an undelcared variable */ if (not_string || str_var(token)) { /* name that includes '$' is also assumed to be a variable */ dbg gprint("Found un-initialized variable {%s} /n",token.c_str()); if (!var_valid_name(uc_token)) { throw error(token_col, "illegal variable name '"+uc_token+"'"); } var_findadd((char*)uc_token.c_str(), &v, &ret); if (ret == 2) pcode.addStrVar(v); else pcode.addVar(v); not_string = true; unary = 2; if (m_vars != NULL && m_vars->try_get(uc_token) == -1) { /* Add it to list of vars */ m_vars->add_item(uc_token, v); } break; } // std::cout << "Unquoted string '" << token << "'" << std::endl; pcode.addString(token); if (!valid_unquoted_string(token)) { throw error(token_col, "invalid unquoted string '"+token+"'"); } isa_string = true; unary = 2; break; case 2: /* a binary operator, or space, or end of line */ /* MIGHT (gives error with a$ = b$+c$) */ if (first_char != '.') { if (isa_string) { throw error("left hand side contains unquoted string"); } not_string = true; } else { not_string = false; } /* Binary operators, +,-,*,/,^,<,>,<=,>=,.and.,.or. */ int priority = 0; if (token_len == 1) { switch (first_char) { case '+' : v = BIN_OP_PLUS; priority = 2; break; case '-' : v = BIN_OP_MINUS; priority = 2; break; case '*' : v = BIN_OP_MULTIPLY; priority = 3; break; case '/' : v = BIN_OP_DIVIDE; priority = 3; break; case '%' : v = BIN_OP_MOD; priority = 3; break; case '^' : v = BIN_OP_POW; priority = 4; break; case '=' : v = BIN_OP_EQUALS; priority = 1; break; case '&' : v = BIN_OP_AND; priority = 1; break; case '|' : v = BIN_OP_OR; priority = 1; break; case '<' : v = BIN_OP_LT; priority = 1; break; case '>' : v = BIN_OP_GT; priority = 1; break; case '.' : v = BIN_OP_DOT; priority = 2; break; default : v = 0; } } else { str_to_uppercase(token, uc_token); if (token == "<=") { v = BIN_OP_LE; priority = 1; } else if (token == "<>") { v = BIN_OP_NOT_EQUALS; priority = 1; } else if (token == ">=") { v = BIN_OP_GE; priority = 1; } else if (token == "**") { v = BIN_OP_POW; priority = 4; } else if (uc_token == "AND") { v = BIN_OP_AND; priority = 1; } else if (uc_token == "OR") { v = BIN_OP_OR; priority = 1; } else { v = 0; } } if (v > 0) { stack_bin(v, priority); dbg gprint("Found binary operator \n"); unary = 1; } else if (first_char == ')' && token_len == 1) { if (curpri > 0) { curpri = curpri - 100; unary = 2; break; } if (!term_bracket) { throw error("too many closing ')', expecting binary operator"); } } else { throw error(string("unknown binary operator '")+token+"'"); } } // end switch } // end for }
/*--------------------------------------------------------*/ int main(int argc, char *argv[]) { char **newheader, *imffname, *parfname, *psffname, *reffname, *instrname, *fieldname, *outfname, *coofname, **diffiles, **imfiles, **kerfiles; int nx0, ny0, k, *sector, nim, iim, npsf, ipsf, hsize, isec_x, isec_y, *cx, *cy, psfn, kern, irad, // ofs, *vnum, i; float *im, *difim, *refim; double **wxy, *x, *y, *xs, *ys, **psfs, *psfim, *kerim, ratio; STAR **obj, *objp; PSF_STRUCT psf; KER_STRUCT ker; PAR_STRUCT par; /*** IO stuff ***/ if (argc != 7) { printf("\n\tUSAGE: phot parameter_file instrument_file"); printf(" ref_image psf_fit_file image_data_list field_name\n"); exit(1); } parfname= argv[1]; instrname=argv[2]; reffname= argv[3]; psffname= argv[4]; imffname= argv[5]; fieldname=argv[6]; get_params(parfname, instrname, &par); if (par.verbose) printf("\n\n*** Profile photometry with variable PSF and kernel ***\n\n"); if (!(outfname=(char *)calloc(strlen(fieldname)+5, sizeof(char)))) errmess("calloc(outfname)"); strcpy(outfname, fieldname); strcat(outfname, ".db"); if (!(coofname=(char *)calloc(strlen(fieldname)+5, sizeof(char)))) errmess("calloc(coofname)"); strcpy(coofname, fieldname); strcat(coofname, ".coo"); /*** read filenames for difference images, images and kernel fits ***/ nim=readfnames(imffname, &diffiles, &imfiles, &kerfiles); if (par.verbose) printf("%d images to process\n", nim); /*** read coordinates of variables ***/ npsf=readcoo(coofname, &vnum, &x, &y); if (par.verbose) printf("%d variables to measure\n\n", npsf); /*** read in psf fit and get a sample kernel from the first image ***/ read_psf(psffname, &psf); read_kernel(kerfiles[0], &ker, 1, par.verbose); psf.normrad = par.normrad; psf.hw += ker.hw; psfn = 2*psf.hw + 1; kern = 2*ker.hw + 1; /*** get memory ***/ if (!(ker.vecs = (double **)malloc(ker.nvecs*sizeof(double *)))) errmess("malloc(ker.vecs)"); for (k=0; k<ker.nvecs; k++) if (!(ker.vecs[k] = (double *)malloc(kern*kern*sizeof(double)))) errmess("malloc(ker.vecs[k])"); if (!(sector=(int *)malloc(npsf*sizeof(int)))) errmess("malloc(sector)"); if (!(cx= (int *)malloc(npsf*sizeof(int)))) errmess("malloc(cx)"); if (!(cy= (int *)malloc(npsf*sizeof(int)))) errmess("malloc(cy)"); if (!(xs= (double *)malloc(npsf*sizeof(double)))) errmess("malloc(xs)"); if (!(ys= (double *)malloc(npsf*sizeof(double)))) errmess("malloc(ys)"); if (!(wxy=(double **)malloc(npsf*sizeof(double *)))) errmess("malloc(wxy)"); if (!(psfs=(double **)malloc(npsf*sizeof(double *)))) errmess("malloc(psfs)"); if (!(kerim=(double *)malloc(kern*kern*sizeof(double)))) errmess("malloc(kerim)"); if (!(psfim=(double *)malloc(psfn*psfn*sizeof(double)))) errmess("malloc(psfim)"); if (!(obj=(STAR **)malloc(npsf*sizeof(STAR *)))) errmess("malloc(obj)"); /***********************************************************************/ /** get things that can be done once for all: spatial coeffs and psfs **/ /***********************************************************************/ for (ipsf=0; ipsf<npsf; ipsf++) { if (!(obj[ipsf]=(STAR *)malloc(nim*sizeof(STAR)))) errmess("malloc(obj[ipsf])"); if (!(wxy[ipsf]=(double *)malloc(ker.nwxy*sizeof(double)))) errmess("malloc(wxy[ipsf])"); if (!(psfs[ipsf]=(double *)malloc(psfn*psfn*sizeof(double)))) errmess("malloc(psfs[ipsf])"); /* offsets for image sectors from kernel fit */ cx[ipsf]=(int)floor(x[ipsf]+0.5); cy[ipsf]=(int)floor(y[ipsf]+0.5); isec_x=(cx[ipsf] - ker.hw)/(ker.nx - 2*ker.hw); isec_y=(cy[ipsf] - ker.hw)/(ker.ny - 2*ker.hw); xs[ipsf]=x[ipsf] - isec_x*(ker.nx - 2*ker.hw); ys[ipsf]=y[ipsf] - isec_y*(ker.ny - 2*ker.hw); sector[ipsf]=isec_y + ker.nsec_y*isec_x; spatial_coeffs(&ker, xs[ipsf], ys[ipsf], wxy[ipsf]); init_psf(&psf, x[ipsf], y[ipsf]); make_psf(&psf, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf], psfs[ipsf]); } refim=read_FITS_2D1file(reffname, 's', &hsize, &newheader, &nx0, &ny0); for (i=0; i<hsize; i++) free(newheader[i]); free(newheader); make_vectors(&ker); par.nx0=nx0; par.ny0=ny0; par.psfhw=psf.hw; par.psfn=psfn; irad=(int)par.anrad2 + 2; /*******************************/ /*** main loop over images ***/ /*******************************/ for (iim=0; iim<nim; iim++) { if (par.verbose > 2) printf("%d: %s\n", iim, diffiles[iim]); difim=read_FITS_2D1file(diffiles[iim], 's', &hsize, &newheader, &nx0, &ny0); for (i=0; i<hsize; i++) free(newheader[i]); free(newheader); if ((nx0 != par.nx0) || (ny0 != par.ny0)) { printf("ERROR! phot: wrong size of the image %s\n", diffiles[iim]); exit(2); } im=read_FITS_2D1file(imfiles[iim], 's', &hsize, &newheader, &nx0, &ny0); for (i=0; i<hsize; i++) free(newheader[i]); free(newheader); if ((nx0 != par.nx0) || (ny0 != par.ny0)) { printf("ERROR! phot: wrong size of the image %s\n", imfiles[iim]); exit(3); } /* read kernel into tables allocated before */ read_kernel(kerfiles[iim], &ker, 0, par.verbose); /*** loop over stars ***/ for (ipsf=0; ipsf<npsf; ipsf++) { objp = &obj[ipsf][iim]; if ((cx[ipsf] < irad) || (cy[ipsf] < irad) || (cx[ipsf] >= nx0-irad) || (cy[ipsf] >= ny0-irad)) { if (par.verbose) printf("%s warning: object %4d too close to edge: ignored!\n", diffiles[iim], ipsf); objp->a_flux = par.bad_value; objp->a_err = par.bad_value; objp->p_flux = par.bad_value; objp->p_err = par.bad_value; objp->chi2_n = par.bad_value; objp->ker_chi2 = par.bad_value; objp->corr = par.bad_value; objp->nbad = -1; continue; } /*** prepare local psf ***/ make_kernel(&ker, wxy[ipsf], kerim, sector[ipsf]); im_convolve(psfs[ipsf], psfim, psfn, psfn, kerim, ker.hw); objp->ker_chi2=(float)ker.chi2_n[sector[ipsf]]; objp->fwhm=(float)get_fwhm(psfim, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf], &par, &ratio); if (par.bkg_mode) objp->bg = bkg(difim, cx[ipsf], cy[ipsf], &par); else objp->bg = 0.0; /*** actual profile and aperture photometry ***/ get_phot(difim, im, refim, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf], psfim, objp, &par); if (par.verbose > 1) printf("%s star: %5d flux= %9g +- %8g nbad: %d\n", diffiles[iim], ipsf, objp->p_flux, objp->p_err, objp->nbad); } free(difim); free(im); } /*** write photometry to the output file ***/ if (par.verbose) printf("\nWriting photometry to: %s\n", outfname); if (par.dbf == 'A') writedba(outfname, diffiles, nim, npsf, vnum, obj); else writedbb(outfname, diffiles, nim, npsf, vnum, obj); if (par.verbose) printf("\nPhotometry done!\n"); return(0); }
int dm_create_device(const char *name, const char *device, const char *cipher, const char *type, const char *uuid, uint64_t size, uint64_t skip, uint64_t offset, size_t key_size, const char *key, int read_only, int reload) { struct dm_task *dmt = NULL; struct dm_info dmi; char *params = NULL; char *error = NULL; char dev_uuid[DM_UUID_LEN] = {0}; int r = -EINVAL; uint32_t read_ahead = 0; uint32_t cookie = 0; uint16_t udev_flags = 0; params = get_params(device, skip, offset, cipher, key_size, key); if (!params) goto out_no_removal; if (type && !strncmp(type, "TEMP", 4)) udev_flags = CRYPT_TEMP_UDEV_FLAGS; /* All devices must have DM_UUID, only resize on old device is exception */ if (reload) { if (!(dmt = dm_task_create(DM_DEVICE_RELOAD))) goto out_no_removal; if (!dm_task_set_name(dmt, name)) goto out_no_removal; } else { dm_prepare_uuid(name, type, uuid, dev_uuid, sizeof(dev_uuid)); if (!(dmt = dm_task_create(DM_DEVICE_CREATE))) goto out_no_removal; if (!dm_task_set_name(dmt, name)) goto out_no_removal; if (!dm_task_set_uuid(dmt, dev_uuid)) goto out_no_removal; if (_dm_use_udev() && !dm_task_set_cookie(dmt, &cookie, udev_flags)) goto out_no_removal; } if (read_only && !dm_task_set_ro(dmt)) goto out_no_removal; if (!dm_task_add_target(dmt, 0, size, DM_CRYPT_TARGET, params)) goto out_no_removal; #ifdef DM_READ_AHEAD_MINIMUM_FLAG if (_dev_read_ahead(device, &read_ahead) && !dm_task_set_read_ahead(dmt, read_ahead, DM_READ_AHEAD_MINIMUM_FLAG)) goto out_no_removal; #endif if (!dm_task_run(dmt)) goto out_no_removal; if (reload) { dm_task_destroy(dmt); if (!(dmt = dm_task_create(DM_DEVICE_RESUME))) goto out; if (!dm_task_set_name(dmt, name)) goto out; if (uuid && !dm_task_set_uuid(dmt, dev_uuid)) goto out; if (_dm_use_udev() && !dm_task_set_cookie(dmt, &cookie, udev_flags)) goto out; if (!dm_task_run(dmt)) goto out; } if (!dm_task_get_info(dmt, &dmi)) goto out; r = 0; out: if (_dm_use_udev()) { (void)dm_udev_wait(cookie); cookie = 0; } if (r < 0 && !reload) { if (get_error()) error = strdup(get_error()); dm_remove_device(name, 0, 0); if (error) { set_error(error); free(error); } } out_no_removal: if (cookie && _dm_use_udev()) (void)dm_udev_wait(cookie); if (params) safe_free(params); if (dmt) dm_task_destroy(dmt); dm_task_update_nodes(); return r; }
/* * tee_open_session - invoke TEE to open a GP TEE session */ static int tz_open(struct tee_session *sess, struct tee_cmd *cmd) { struct tee *tee; struct tee_tz *ptee; int ret = 0; struct teesmc32_arg *arg32; struct teesmc32_param *params32; struct teesmc_meta_open_session *meta; uintptr_t parg32; uintptr_t pmeta; size_t num_meta = 1; uint8_t *ta; TEEC_UUID *uuid; BUG_ON(!sess->ctx->tee); BUG_ON(!sess->ctx->tee->priv); tee = sess->ctx->tee; ptee = tee->priv; if (cmd->uuid) uuid = cmd->uuid->kaddr; else uuid = NULL; dev_dbg(tee->dev, "> ta kaddr %p, uuid=%08x-%04x-%04x\n", (cmd->ta) ? cmd->ta->kaddr : NULL, ((uuid) ? uuid->timeLow : 0xDEAD), ((uuid) ? uuid->timeMid : 0xDEAD), ((uuid) ? uuid->timeHiAndVersion : 0xDEAD)); if (!CAPABLE(ptee->tee)) { dev_dbg(tee->dev, "< not capable\n"); return -EBUSY; } /* case ta binary is inside the open request */ ta = NULL; if (cmd->ta) ta = cmd->ta->kaddr; if (ta) num_meta++; arg32 = alloc_tee_arg(ptee, &parg32, TEESMC32_GET_ARG_SIZE( TEEC_CONFIG_PAYLOAD_REF_COUNT + num_meta)); meta = alloc_tee_arg(ptee, &pmeta, sizeof(*meta)); if ((arg32 == NULL) || (meta == NULL)) { free_tee_arg(ptee, parg32); free_tee_arg(ptee, pmeta); return TEEC_ERROR_OUT_OF_MEMORY; } memset(arg32, 0, sizeof(*arg32)); memset(meta, 0, sizeof(*meta)); arg32->num_params = TEEC_CONFIG_PAYLOAD_REF_COUNT + num_meta; params32 = TEESMC32_GET_PARAMS(arg32); arg32->cmd = TEESMC_CMD_OPEN_SESSION; params32[0].u.memref.buf_ptr = pmeta; params32[0].u.memref.size = sizeof(*meta); params32[0].attr = TEESMC_ATTR_TYPE_MEMREF_INPUT | TEESMC_ATTR_META | get_cache_attrs(ptee); if (ta) { params32[1].u.memref.buf_ptr = tee_shm_pool_v2p(DEV, ptee->shm_pool, cmd->ta->kaddr); params32[1].u.memref.size = cmd->ta->size_req; params32[1].attr = TEESMC_ATTR_TYPE_MEMREF_INPUT | TEESMC_ATTR_META | get_cache_attrs(ptee); } if (uuid != NULL) memcpy(meta->uuid, uuid, TEESMC_UUID_LEN); meta->clnt_login = 0; /* FIXME: is this reliable ? used ? */ params32 += num_meta; set_params(ptee, params32, cmd->param.type, &cmd->param); call_tee(ptee, parg32, arg32); get_params(&cmd->param, params32); if (arg32->ret != TEEC_ERROR_COMMUNICATION) { sess->sessid = arg32->session; cmd->err = arg32->ret; cmd->origin = arg32->ret_origin; } else ret = -EBUSY; free_tee_arg(ptee, parg32); free_tee_arg(ptee, pmeta); dev_dbg(DEV, "< %x:%d\n", arg32->ret, ret); return ret; }
int main(int argc, char* argv[]) { signal( SIGTRAP, SIG_IGN ); params p = get_params( argc, argv ); unistd::addrinfo hint = addrinfo{ 0, AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, 0, nullptr, nullptr, nullptr }; std::vector<unistd::addrinfo> addrs = unistd::getaddrinfo( p.hostname, p.port, hint ); const unistd::addrinfo& addr = addrs.at( 0 ); unistd::fd sock = unistd::socket( addr ); subscribe_events( sock ); if ( 0 != p.sndbuf ) unistd::setsockopt( sock, SOL_SOCKET, SO_SNDBUF, p.sndbuf ); if ( 0 != p.mtu ) { unistd::setsockopt( sock, IPPROTO_IPV6, IPV6_MTU_DISCOVER, IP_PMTUDISC_DONT ); unistd::setsockopt( sock, IPPROTO_IPV6, IPV6_MTU, p.mtu ); } if ( p.nodelay ) unistd::setsockopt( sock, SOL_SCTP, SCTP_NODELAY, 1 ); if ( 0 != p.max_burst ) unistd::setsockopt( sock, SOL_SCTP, SCTP_MAX_BURST, p.max_burst ); if ( 0 != p.maxseg ) unistd::setsockopt( sock, SOL_SCTP, SCTP_MAXSEG, p.maxseg ); int sndbuf = 0; socklen_t len = sizeof(sndbuf); getsockopt( sock, SOL_SOCKET, SO_SNDBUF, &sndbuf, &len ); fprintf( stderr, "sndbuf: set=%d get=%d\n", p.sndbuf, sndbuf ); if ( 0 != p.rcvbuf ) unistd::setsockopt( sock, SOL_SOCKET, SO_RCVBUF, p.rcvbuf ); sctp_initmsg init_params; memset( &init_params, 0, sizeof(init_params) ); init_params.sinit_num_ostreams = 1; init_params.sinit_max_instreams = 1; init_params.sinit_max_attempts = 3; init_params.sinit_max_init_timeo = 100; unistd::setsockopt( sock, SOL_SCTP, SCTP_INITMSG, init_params ); unistd::connect( sock, addr ); sctp_assoc_t assoc_id = 0; while ( assoc_id == 0 ) { std::vector<char> cmsg_buff( CMSG_SPACE( sizeof( sctp_sndrcvinfo ) ) ); std::vector<char> msg_buff( 8192 ); //TODO: struct iovec iov; memset( &iov, 0, sizeof(iov) ); iov.iov_base = msg_buff.data(); iov.iov_len = msg_buff.size(); struct msghdr hdr; memset( &hdr, 0, sizeof(hdr) ); hdr.msg_name = nullptr; hdr.msg_namelen = 0; hdr.msg_iov = &iov; hdr.msg_iovlen = 1; hdr.msg_control = cmsg_buff.data(); hdr.msg_controllen = cmsg_buff.size(); hdr.msg_flags = 0; ssize_t nrecv = 0; TEMP_FAILURE_RETRY( nrecv = recvmsg( sock, &hdr, 0 ) ); if ( 0 == nrecv ) raise( SIGTRAP ); if ( -1 == nrecv ) raise( SIGTRAP ); if ( hdr.msg_flags & MSG_NOTIFICATION ) { const sctp_notification& notify = *reinterpret_cast<const sctp_notification*>( hdr.msg_iov[0].iov_base ); switch ( notify.sn_header.sn_type ) { case SCTP_ASSOC_CHANGE: { const auto& sac = notify.sn_assoc_change; std::cout << " assoc_id=" << sac.sac_assoc_id << " error=" << sac.sac_error << " in=" << sac.sac_inbound_streams << " out=" << sac.sac_outbound_streams << std::endl; assoc_id = sac.sac_assoc_id; break; } case SCTP_REMOTE_ERROR: { const auto& sre = notify.sn_remote_error; printf( "^^^ remote_error: err=%hu len=%hu\n", ntohs(sre.sre_error), ntohs(sre.sre_length) ); return EXIT_FAILURE; } case SCTP_SHUTDOWN_EVENT: { printf( "^^^ SCTP_SHUTDOWN_EVENT\n" ); return EXIT_FAILURE; } } } } //int flags = fcntl( sock, F_GETFL, 0 ); //fcntl( sock, F_SETFL, flags | O_NONBLOCK ); const std::vector<char> msg = generate_message( p.msgsize ); struct iovec iov; iov.iov_base = const_cast<char*>( msg.data() ); iov.iov_len = msg.size(); std::vector<char> cmsg_buff( CMSG_SPACE( sizeof( sctp_sndrcvinfo ) ) ); struct mmsghdr mhdr; memset( &mhdr, 0, sizeof(mhdr) ); struct msghdr& hdr = mhdr.msg_hdr; hdr.msg_name = nullptr; hdr.msg_namelen = 0; hdr.msg_iov = &iov; hdr.msg_iovlen = 1; hdr.msg_flags = 0; hdr.msg_control = cmsg_buff.data(); hdr.msg_controllen = cmsg_buff.size(); cmsghdr* cmsg = CMSG_FIRSTHDR( &hdr ); cmsg->cmsg_level = IPPROTO_SCTP; cmsg->cmsg_type = SCTP_SNDRCV; cmsg->cmsg_len = CMSG_LEN( sizeof( sctp_sndrcvinfo ) ); sctp_sndrcvinfo& cmsg_data = *reinterpret_cast<sctp_sndrcvinfo*>( CMSG_DATA( cmsg ) ); cmsg_data.sinfo_stream = 0; cmsg_data.sinfo_ssn = 0; //ignored cmsg_data.sinfo_flags = SCTP_UNORDERED; cmsg_data.sinfo_ppid = 31337; cmsg_data.sinfo_context = 123456; cmsg_data.sinfo_timetolive = 0; cmsg_data.sinfo_tsn = 0; //ignored cmsg_data.sinfo_cumtsn = 0; //ignored cmsg_data.sinfo_assoc_id = assoc_id; std::vector<mmsghdr> mhdrs( p.batch, mhdr ); while ( p.count ) { const ssize_t count = std::min<uint64_t>( p.batch, p.count ); ssize_t nsend = 0; TEMP_FAILURE_RETRY( nsend = sendmmsg( sock, mhdrs.data(), count, 0 ) ); if ( 0 == nsend ) raise( SIGTRAP ); if ( -1 == nsend ) raise( SIGTRAP ); if ( count != nsend ) raise( SIGTRAP ); p.count -= count; } //raise( SIGTRAP ); sock.close(); return EXIT_SUCCESS; }
int main (int argc, char **argv) { char command [CMD_SIZE]; int initialize_tape = 1; int tape_status = 5; int status; unsigned char *beam_ptr; int first_time = TRUE; LL_beam_rec *enet_pak; extern process_exit(); extern print_target_elev (); /* trap signals */ (void) signal (SIGINT, ((void (*) ()) process_exit)); (void) signal (SIGHUP, ((void (*) ()) process_exit)); (void) signal (SIGTERM, ((void (*) ()) process_exit)); enet_pak = (LL_beam_rec *) malloc ((unsigned) sizeof (LL_beam_rec)); if (enet_pak == NULL) { (void) printf ("Malloc error \n"); return (-1); } if ((!get_params (&Glob))) exit (2); /* initialize streams (fmq and/or shmem) for sending beam data */ if (init_streams ()) { (void) fprintf (stderr, "streams initialization error"); return (1); } if (system ("clear") != 0) perror ("clear"); /* Determine the source of the data to be reformatted */ if (!Glob.real_time) { /* initialize the shared memory for receiving commands*/ if (recv_cmd (1, Glob.cmd_shmem_key, (unsigned char **) &command) == -1) { (void) printf ("recv_cmd fatal error\n"); exit (-1); } for (;;) { if ((status = get_shm_cmd (command)) > 0) break; else if (first_time) { first_time = FALSE; (void) printf ("waiting for menu process to send start command\n"); } sleep (2); } source = parse_settings (command, &Glob); if (source < 0) return (0); } else source = RADAR; switch (source) { case RADAR: if (recv_shm (1, Glob.input_shmem_key, &beam_ptr)) { (void) printf ("recv_shm fatal error\n"); exit (-1); } for (;go ;) { if (get_shmem_data (enet_pak, Glob.input_shmem_key) == 0) { if (first_time) { (void) printf ("waiting for data\n"); first_time = FALSE; } usleep (no_packet); } /* Check for a stop command */ if (!Glob.real_time) { if ((status = get_shm_cmd (command)) > 0) { source = parse_settings (command, &Glob); if (source < 0) go = 0; if (source == FLAG_CHANGE) { (void) printf ("\n Flag status: Dealias failure = %s\n", Glob.caf ? "TRUE":"FALSE"); (void) printf (" Point Target = %s\n", Glob.ctf ? "TRUE":"FALSE"); (void) printf (" SNR thresholding = %s\n", Glob.cvf ? "TRUE":"FALSE"); (void) printf (" Clutter = %s\n", Glob.ccv ? "TRUE":"FALSE"); (void) printf (" low PRF in valid gate = %s\n\n", Glob.cv ? "TRUE":"FALSE"); } } } } break; case TAPE: if (Glob.remote_tape) { if (tape_init (&fd_tape, Glob.tape_device)) { (void) printf("Error initializing the tape device %s", Glob.tape_device); source = -1; return (0); } } for (;go ;) { if (initialize_tape) { initialize_tape = FALSE; tape_command (); } tape_status = get_tape_data (fd_tape, data_rate, enet_pak); switch (tape_status) { case 0: /* automatically rewind the tape * when end of tape is detected */ /* tape_rewind = REWIND; initialize_tape = TRUE; */ /* or stop the system at the end of the tape */ (void) printf ("Received STOP command \n"); go = 0; exit (0); break; case INITIALIZE_RMT: (void) close (fd_tape); if (tape_init (&fd_tape, Glob.tape_device)) { (void) printf("Error initializing the tape device %s", Glob.tape_device); source = -1; return (0); } break; case INITIALIZE: initialize_tape = TRUE; break; case REWIND: /*go = 0; exit (0); break;*/ tape_rewind = REWIND; initialize_tape = TRUE; break; case TAPE_ERR: (void) printf ("Tape read error / received STOP command \n"); go = 0; break; case RATE_CHANGE: initialize_tape = FALSE; break; case PAUSE: for (;;) { if (Glob.remote_tape) { (void) rmt_close (); } if ((status = get_shm_cmd (command)) > 0) { if (Glob.remote_tape) { if (tape_init (&fd_tape, Glob.tape_device)) { (void) printf("Error initializing the tape device %s", Glob.tape_device); go = 0; } } break; } else usleep (3000); } break; case FLAG_CHANGE: (void) printf ("\n Flag status: Dealias failure = %s\n", Glob.caf ? "TRUE":"FALSE"); (void) printf (" Point Target = %s\n", Glob.ctf ? "TRUE":"FALSE"); (void) printf (" SNR thresholding = %s\n", Glob.cvf ? "TRUE":"FALSE"); (void) printf (" Clutter = %s\n", Glob.ccv ? "TRUE":"FALSE"); (void) printf (" low PRF in valid gate = %s\n\n", Glob.cv ? "TRUE":"FALSE"); } } break; default: (void) printf ("source unrecognized \n"); break; } return (0); }
int parse_cla(int argc,char *argv[],struct ARDOP_PARAMS *g,meta_parameters **meta_out) { int read_offset = 0, /* Flag - Read resampling offsets from file? */ read_dopplr = 0; /* Flag - Read doppler constant from file? */ int cal_check=0; /* checks if output file needs input cal file */ int debug_help=-1; /* If -debug 0 used, give debug usage */ char fName_slope[256], /* Input slope,intercept (offsets) file */ fName_doppler[256]; /* Input doppler constant file */ FILE *fp; meta_parameters *meta; /* Preset Optional Command Line Parameters ---------------------------------------------------------*/ g->hamFlag=0; g->kaiFlag=0; g->pwrFlag=0; g->sigmaFlag=0; g->gammaFlag=0; g->betaFlag=0; g->nextend=0.0; g->pctbw=g->pctbwaz=0.0; g->fd=0; g->fdd=-99; /*Doppler slope of -99 means to figure it out ourselves.*/ g->fddd=-99; /*Doppler slope of -99 means to figure it out ourselves.*/ g->ifirstline = 0; /* First line to process */ g->npatches = 100; /* (Absurdly Large) Number of patches */ g->ifirst = 0; /* i,q byte samples to skip */ g->isave = 0; /* start range bin */ g->na_valid = -99; /* Valid output samples per patch (-99->determine)*/ g->iflag = 1; /* Debug Flag */ g->deskew=0; g->sloper = g->interr = g->slopea = g->intera = 0.0; g->dsloper = g->dinterr = g->dslopea = g->dintera = 0.0; strcpy(g->CALPRMS,"NO"); /* Process the Command Line Arguments ------------------------------------*/ if (argc<3) {printf("Must give input and output filenames.\n");return 0;} strcpy(g->in1,argv[argc-2]); strcpy(g->out,argv[argc-1]); /*Create ARDOP_PARAMS struct as well as meta_parameters.*/ if (extExists(g->in1,".in")) {/*Read parameters from parameter file*/ read_params(g->in1,g); if (extExists(g->in1,".meta"))/*Input file has .meta attached: read it*/ meta=meta_read(g->in1); else /*No .meta exists--fabricate one*/ meta=raw_init(); } else /*Read parameters & .meta from CEOS.*/ get_params(g->in1,g,&meta); while (currArg < (argc-2)) { char *key=argv[currArg++]; if (strmatch(key,"-log")) {CHK_ARG_ASP(1); strcpy(logFile, GET_ARG(1)); logflag = 1; fLog = FOPEN(logFile, "a");} else if (strmatch(key,"-debug")) { CHK_ARG_ASP(1); g->iflag = atoi(GET_ARG(1)); if (g->iflag==0) return debug_help; } else if (strmatch(key,"-quiet")) {quietflag = 1;} else if (strmatch(key,"-power")) {g->pwrFlag=1;} else if (strmatch(key,"-sigma")) {g->sigmaFlag=1; cal_check=1;} else if (strmatch(key,"-gamma")) {g->gammaFlag=1; cal_check=1;} else if (strmatch(key,"-beta" )) {g->betaFlag=1; cal_check=1;} else if (strmatch(key,"-hamming")) {g->hamFlag = 1;} else if (strmatch(key,"-kaiser")) {g->kaiFlag = 1;} else if (strmatch(key,"-l")) {CHK_ARG_ASP(1); g->ifirstline = atoi(GET_ARG(1));} else if (strmatch(key,"-p")) {CHK_ARG_ASP(1); g->npatches = atoi(GET_ARG(1));} else if (strmatch(key,"-f")) {CHK_ARG_ASP(1); g->isave += atoi(GET_ARG(1));} else if (strmatch(key,"-s")) {CHK_ARG_ASP(1); g->ifirst += atoi(GET_ARG(1));} else if (strmatch(key,"-n")) {CHK_ARG_ASP(1); g->nla = atoi(GET_ARG(1));} else if (strmatch(key,"-r")) {CHK_ARG_ASP(1); g->azres = atof(GET_ARG(1));} else if (strmatch(key,"-e")) {CHK_ARG_ASP(1); g->deskew = atoi(GET_ARG(1)); g->na_valid =-99;} /* If you use the -e flag, then a deskew wedge in the data will need to be removed. Override internal measurement of the number of valid azimuth lines with the -v option flag */ else if (strmatch(key,"-v")) {CHK_ARG_ASP(1); g->na_valid = atoi(GET_ARG(1));} else if (strmatch(key,"-o")) {CHK_ARG_ASP(1); strcpy(fName_slope,GET_ARG(1)); read_offset = 1;} else if (strmatch(key,"-c")) {CHK_ARG_ASP(1); strcpy(fName_doppler,GET_ARG(1)); read_dopplr = 1;} else if (strmatch(key,"-m")) {CHK_ARG_ASP(1);strcpy(g->CALPRMS,GET_ARG(1));} else {printf("**Invalid option: %s\n\n",argv[currArg-1]); return 0;} } if ((strcmp(g->CALPRMS,"NO")==0)&&(cal_check==1)) { printf(" You can only use -sigma, -beta, or -gamma in conjunction with -m\n"); printf(" I will proceed, ignoring the option.\n"); g->sigmaFlag=0; g->gammaFlag=0; g->betaFlag=0; } if (read_offset) { fp=FOPEN(fName_slope,"r"); fscanf(fp,"%f %f %f %f",&g->sloper,&g->interr,&g->slopea,&g->intera); fscanf(fp,"%g %g %g %g",&g->dsloper,&g->dinterr,&g->dslopea,&g->dintera); FCLOSE(fp); } if (read_dopplr) { fp=FOPEN(fName_doppler,"r"); g->fd=g->fdd=g->fddd=0.0; fscanf(fp,"%f %f %f", &g->fd,&g->fdd,&g->fddd); FCLOSE(fp); } /*Copy fields from ARDOP_PARAMS struct to meta_parameters struct.*/ meta->sar->image_type = 'S'; /*Slant range image*/ meta->sar->azimuth_look_count = g->nlooks; meta->sar->range_look_count = 1; meta->sar->deskewed = g->deskew; meta->sar->range_time_per_pixel = 1.0/g->fs; meta->sar->azimuth_time_per_pixel = 1.0/g->prf; meta->sar->slant_shift = g->slantOff; meta->sar->time_shift = g->timeOff; meta->sar->slant_range_first_pixel = g->r00; meta->sar->wavelength = g->wavl; meta->sar->prf = g->prf; meta->sar->earth_radius = g->re; meta->sar->satellite_height = g->re+g->ht; meta->sar->range_doppler_coefficients[0] = g->fd*g->prf; meta->sar->range_doppler_coefficients[1] = g->fdd*g->prf; meta->sar->range_doppler_coefficients[2] = g->fddd*g->prf; meta->sar->azimuth_doppler_coefficients[0] = g->fd*g->prf; meta->sar->azimuth_doppler_coefficients[1] = 0.0; meta->sar->azimuth_doppler_coefficients[2] = 0.0; meta->general->data_type = REAL32; meta->general->band_count = 1; meta->general->x_pixel_size = meta->sar->range_time_per_pixel * (speedOfLight/2.0); meta->general->y_pixel_size = meta->sar->azimuth_time_per_pixel * g->vel * (g->re/g->ht); *meta_out = meta; return 1; }
int main(int argc, char *argv[]) { int status; struct app_params p; size_t i; struct bladerf *dev = NULL; bladerf_xb expected, attached; struct stats *stats = NULL; bool pass = true; status = get_params(argc, argv, &p); if (status != 0) { if (status == 1) { status = 0; } goto out; } for (i = 0; i < ARRAY_SIZE(tests); i++) { if (p.test_name == NULL || !strcasecmp(p.test_name, tests[i]->name)) { break; } } if (i >= ARRAY_SIZE(tests)) { fprintf(stderr, "Invalid test: %s\n", p.test_name); status = -1; goto out; } stats = calloc(ARRAY_SIZE(tests), sizeof(stats[0])); if (stats == NULL) { perror("calloc"); status = -1; goto out; } status = bladerf_open(&dev, p.device_str); if (status != 0) { fprintf(stderr, "Failed to open device: %s\n", bladerf_strerror(status)); goto out; } if (p.use_xb200) { expected = BLADERF_XB_200; status = bladerf_expansion_attach(dev, BLADERF_XB_200); if (status != 0) { fprintf(stderr, "Failed to attach XB-200: %s\n", bladerf_strerror(status)); goto out; } } else { expected = BLADERF_XB_NONE; } status = bladerf_expansion_get_attached(dev, &attached); if (status != 0) { fprintf(stderr, "Failed to query attached expansion board: %s\n", bladerf_strerror(status)); goto out; } if (expected != attached) { fprintf(stderr, "Unexpected expansion board readback: %d\n", attached); status = -1; goto out; } for (i = 0; i < ARRAY_SIZE(tests); i++) { if (p.test_name == NULL || !strcasecmp(p.test_name, tests[i]->name)) { p.randval_state = p.randval_seed; stats[i].ran = true; stats[i].failures = tests[i]->fn(dev, &p, false); } } puts("\nFailure counts"); puts("--------------------------------------------"); for (i = 0; i < ARRAY_SIZE(tests); i++) { if (stats[i].ran) { printf("%16s %u\n", tests[i]->name, stats[i].failures); } if (stats[i].failures != 0) { pass = false; } } puts(""); status = pass ? 0 : -1; out: if (dev) { bladerf_close(dev); } free(p.device_str); free(p.test_name); free(stats); return status; }
int main(int argc, char** argv) { sim_param_t params; if (get_params(argc, argv, ¶ms) != 0) exit(-1); // Create global sim_state_t* globalState = init_particles(¶ms); #pragma omp parallel shared(globalState, params) { int proc = omp_get_thread_num(); int nproc = omp_get_num_threads(); FILE* fp = fopen(params.fname, "w"); int nframes = params.nframes; int npframe = params.npframe; float dt = params.dt; int n = globalState->n; // Processor information and holder proc_info* pInfo = malloc(sizeof(proc_info)); pInfo->proc = proc; pInfo->nproc = nproc; pInfo->beg = round((proc/(double)nproc)*n); pInfo->end = round(((proc+1)/(double)nproc)*n); pInfo->forceAccu = calloc(3*n, sizeof(float)); // Never used this... if (proc == 0) { printf("Running in parallel with %d processor\n", nproc); } normalize_mass(globalState, pInfo, ¶ms); double t_start = omp_get_wtime(); if (proc == 0) { // We only write for one processor write_header(fp, n, nframes, params.h); write_frame_data(fp, n, globalState, NULL); } if (proc == 0) { hash_particles(globalState, params.h); } //hash_particles_parallel(globalState, pInfo, params.h); #pragma omp barrier // Need the hashing to be done compute_accel(globalState, pInfo, ¶ms); #pragma omp barrier leapfrog_start(globalState, pInfo, dt); check_state(globalState, pInfo); for (int frame = 1; frame < nframes; ++frame) { // We sort according to Z-Morton to ensure locality, need to implement paralle qsort if (frame % 5 == 0) { // Dividing into chunks of sorting each chunk // This alone turned out to better than sorting the entire array qsort(globalState->part+pInfo->beg, pInfo->end-pInfo->beg ,sizeof(particle_t),compPart); // Sorting the array consisting of sorted chunks // This turned out to actually lower the performance. That's why // I commented it. // #pragma omp barrier // if( pInfo->nproc >1 ) arraymerge(globalState->part, globalState->n, pInfo); //#pragma omp barrier*/ // Serial version /*#pragma omp single // Implied barrier qsort(globalState->part, n, sizeof(particle_t), compPart);*/ } /*else if (frame % 49) {*/ /*if (proc == 0) {*/ /*}*/ /*}*/ #pragma omp barrier // Need sort to finish for (int i = 0; i < npframe; ++i) { if (proc == 0 && npframe % 4 == 0) { // Ammortize hashing cost hash_particles(globalState, params.h); } #pragma omp barrier compute_accel(globalState, pInfo, ¶ms); leapfrog_step(globalState, pInfo, dt); check_state(globalState, pInfo); #pragma omp barrier } if (proc == 0) { printf("Frame: %d of %d - %2.1f%%\n",frame, nframes, 100*(float)frame/nframes); write_frame_data(fp, n, globalState, NULL); } } double t_end = omp_get_wtime(); if (proc == 0) { printf("Ran in %g seconds\n", t_end-t_start); } free(pInfo); fclose(fp); } free_state(globalState); }
int main(int argc, char** argv) { unsigned i; unsigned num_put = 0; struct timeval tv; double sum = 0; double min_time_per_op = -1; double min_of_max = -1; gettimeofday(&tv, 0); srandom(tv.tv_usec); grt_random_init(); int got_params = get_params(); hashset_init(argc, argv, params[SHARE_POWER]); if (!got_params) { if (grt_id == 0) { fprintf(stderr, "*** USING DEFAULT PARAMETERS ***\n"); } grt_barrier(); } numbers = malloc(MY_NUM_OPS * sizeof(grt_word_t)); put_flags = malloc(MY_NUM_OPS * sizeof(grt_bool_t)); int nth = 2*grt_distrib_start(params[NUM_OPS])+1; grt_random_nth(grt_distrib_start(nth)); for (i = 0; i < MY_NUM_OPS; ++i) { unsigned flag_val; numbers[i] = RAND_MAX * grt_random_next(); flag_val = ceil(100 * grt_random_next()); put_flags[i] = (flag_val <= params[PERCENT_PUT]) ? GRT_TRUE : GRT_FALSE; if (put_flags[i] == GRT_TRUE) ++num_put; } grt_barrier(); if (grt_id == 0) { printf("User-specified parameters:\n"); for (i = 0; i < NUM_PARAMS; ++i) { const char *name = param_names[i]; unsigned param = params[i]; printf(" %s=", name); if (i == ON_PTHREAD) printf((param == GRT_TRUE) ? "yes" : "no"); else printf("%u", param); printf("\n"); } printf(" grt_num_procs=%u\n", grt_num_procs); } grt_barrier(); //grt_debug_print("%u/%u puts\n", num_put, MY_NUM_OPS); //grt_barrier(); times = (grt_word_t*) grt_all_alloc(0, grt_num_procs * sizeof(grt_word_t)); for (i = 0; i < params[NUM_RUNS]; ++i) { if (grt_id == 0) { printf("\nRUN NUMBER %u\n\n", i); fflush(stdout); } BARRIER(); run(); if (grt_id == 0) { sum += time_per_op; if (min_time_per_op == -1 || time_per_op < min_time_per_op) min_time_per_op = time_per_op; if (min_of_max == -1 || max_time < min_of_max) min_of_max = max_time; } } BARRIER(); if (grt_id == 0) { printf("\nSUMMARY RESULTS\n\n"); printf("average time per operation=%f us\n", sum / params[NUM_RUNS]); printf("min time per op=%f us\n", min_time_per_op); printf("min of max=%f us\n", min_of_max); } hashset_exit(0); }
int main(int argc, char *argv[]) { struct rooted_tree *tree; struct parameters params; struct h_data depths; params = get_params(argc, argv); /* I could take the switch out of the loop, since the distance type * is fixed for the process's lifetime. OTOH the code is easier to * understand this way, and it's unlikely the switch has a visible * impact on performance. */ while ((tree = parse_tree()) != NULL) { alloc_simple_node_pos(tree); depths = set_node_depth_cb(tree, set_simple_node_pos_depth, get_simple_node_pos_depth); if (FAILURE == depths.status) { perror(NULL); exit(EXIT_FAILURE); } struct rnode *lca_node; struct llist *selected_nodes; if (ARGV_LABELS == params.selection) { selected_nodes = nodes_from_labels(tree, params.labels); if (NULL == selected_nodes) { perror(NULL); exit(EXIT_FAILURE); } } else { selected_nodes = get_selected_nodes(tree, params.selection); } switch (params.distance_method) { case FROM_ROOT: print_distance_list(tree->root, selected_nodes, params.list_orientation, params.show_header); break; case FROM_LCA: /* if no lbl given, use root as LCA */ /* I don't remember why I did it like that, and I * don't see what it is good for, so I discard it. */ /* if (0 == params.labels->count) { lca_node = tree->root; } else { lca_node = lca_from_nodes(tree, selected_nodes); } */ lca_node = lca_from_nodes(tree, selected_nodes); if (NULL == lca_node) { perror(NULL); exit(EXIT_FAILURE); } print_distance_list(lca_node, selected_nodes, params.list_orientation, params.show_header); break; case MATRIX: switch (params.matrix_shape) { case SQUARE: print_square_distance_matrix(tree, selected_nodes, params.show_header); break; case TRIANGLE: print_triangular_distance_matrix(tree, selected_nodes, params.show_header); break; default: fprintf(stderr, "ERROR: unknown matrix form %d\n", params.matrix_shape); exit(EXIT_FAILURE); } break; case FROM_PARENT: print_distance_list(NULL, selected_nodes, params.list_orientation, params.show_header); break; default: fprintf (stderr, "ERROR: invalid distance type '%d'.\n", params.distance_method); exit(EXIT_FAILURE); } destroy_llist(selected_nodes); destroy_all_rnodes(NULL); destroy_tree(tree); } destroy_llist(params.labels); return 0; }
/* convert sixel data into indexed pixel bytes and palette data */ MagickBooleanType sixel_decode(unsigned char /* in */ *p, /* sixel bytes */ unsigned char /* out */ **pixels, /* decoded pixels */ size_t /* out */ *pwidth, /* image width */ size_t /* out */ *pheight, /* image height */ unsigned char /* out */ **palette, /* ARGB palette */ size_t /* out */ *ncolors /* palette size (<= 256) */) { int n, i, r, g, b, sixel_vertical_mask, c; int posision_x, posision_y; int max_x, max_y; int attributed_pan, attributed_pad; int attributed_ph, attributed_pv; int repeat_count, color_index, max_color_index = 2, background_color_index; int param[10]; int sixel_palet[SIXEL_PALETTE_MAX]; unsigned char *imbuf, *dmbuf; int imsx, imsy; int dmsx, dmsy; int y; posision_x = posision_y = 0; max_x = max_y = 0; attributed_pan = 2; attributed_pad = 1; attributed_ph = attributed_pv = 0; repeat_count = 1; color_index = 0; background_color_index = 0; imsx = 2048; imsy = 2048; imbuf = (unsigned char *) AcquireQuantumMemory(imsx * imsy,1); if (imbuf == NULL) { return(MagickFalse); } for (n = 0; n < 16; n++) { sixel_palet[n] = sixel_default_color_table[n]; } /* colors 16-231 are a 6x6x6 color cube */ for (r = 0; r < 6; r++) { for (g = 0; g < 6; g++) { for (b = 0; b < 6; b++) { sixel_palet[n++] = SIXEL_RGB(r * 51, g * 51, b * 51); } } } /* colors 232-255 are a grayscale ramp, intentionally leaving out */ for (i = 0; i < 24; i++) { sixel_palet[n++] = SIXEL_RGB(i * 11, i * 11, i * 11); } for (; n < SIXEL_PALETTE_MAX; n++) { sixel_palet[n] = SIXEL_RGB(255, 255, 255); } (void) ResetMagickMemory(imbuf, background_color_index, imsx * imsy); while (*p != '\0') { if ((p[0] == '\033' && p[1] == 'P') || *p == 0x90) { if (*p == '\033') { p++; } p = get_params(++p, param, &n); if (*p == 'q') { p++; if (n > 0) { /* Pn1 */ switch(param[0]) { case 0: case 1: attributed_pad = 2; break; case 2: attributed_pad = 5; break; case 3: attributed_pad = 4; break; case 4: attributed_pad = 4; break; case 5: attributed_pad = 3; break; case 6: attributed_pad = 3; break; case 7: attributed_pad = 2; break; case 8: attributed_pad = 2; break; case 9: attributed_pad = 1; break; } } if (n > 2) { /* Pn3 */ if (param[2] == 0) { param[2] = 10; } attributed_pan = attributed_pan * param[2] / 10; attributed_pad = attributed_pad * param[2] / 10; if (attributed_pan <= 0) attributed_pan = 1; if (attributed_pad <= 0) attributed_pad = 1; } } } else if ((p[0] == '\033' && p[1] == '\\') || *p == 0x9C) { break; } else if (*p == '"') { /* DECGRA Set Raster Attributes " Pan; Pad; Ph; Pv */ p = get_params(++p, param, &n); if (n > 0) attributed_pad = param[0]; if (n > 1) attributed_pan = param[1]; if (n > 2 && param[2] > 0) attributed_ph = param[2]; if (n > 3 && param[3] > 0) attributed_pv = param[3]; if (attributed_pan <= 0) attributed_pan = 1; if (attributed_pad <= 0) attributed_pad = 1; if (imsx < attributed_ph || imsy < attributed_pv) { dmsx = imsx > attributed_ph ? imsx : attributed_ph; dmsy = imsy > attributed_pv ? imsy : attributed_pv; dmbuf = (unsigned char *) AcquireQuantumMemory(dmsx * dmsy,1); if (dmbuf == (unsigned char *) NULL) { imbuf = (unsigned char *) RelinquishMagickMemory(imbuf); return (MagickFalse); } (void) ResetMagickMemory(dmbuf, background_color_index, dmsx * dmsy); for (y = 0; y < imsy; ++y) { (void) CopyMagickMemory(dmbuf + dmsx * y, imbuf + imsx * y, imsx); } imbuf = (unsigned char *) RelinquishMagickMemory(imbuf); imsx = dmsx; imsy = dmsy; imbuf = dmbuf; } } else if (*p == '!') { /* DECGRI Graphics Repeat Introducer ! Pn Ch */ p = get_params(++p, param, &n); if (n > 0) { repeat_count = param[0]; } } else if (*p == '#') { /* DECGCI Graphics Color Introducer # Pc; Pu; Px; Py; Pz */ p = get_params(++p, param, &n); if (n > 0) { if ((color_index = param[0]) < 0) { color_index = 0; } else if (color_index >= SIXEL_PALETTE_MAX) { color_index = SIXEL_PALETTE_MAX - 1; } } if (n > 4) { if (param[1] == 1) { /* HLS */ if (param[2] > 360) param[2] = 360; if (param[3] > 100) param[3] = 100; if (param[4] > 100) param[4] = 100; sixel_palet[color_index] = hls_to_rgb(param[2] * 100 / 360, param[3], param[4]); } else if (param[1] == 2) { /* RGB */ if (param[2] > 100) param[2] = 100; if (param[3] > 100) param[3] = 100; if (param[4] > 100) param[4] = 100; sixel_palet[color_index] = SIXEL_XRGB(param[2], param[3], param[4]); } } } else if (*p == '$') { /* DECGCR Graphics Carriage Return */ p++; posision_x = 0; repeat_count = 1; } else if (*p == '-') { /* DECGNL Graphics Next Line */ p++; posision_x = 0; posision_y += 6; repeat_count = 1; } else if (*p >= '?' && *p <= '\177') { if (imsx < (posision_x + repeat_count) || imsy < (posision_y + 6)) { int nx = imsx * 2; int ny = imsy * 2; while (nx < (posision_x + repeat_count) || ny < (posision_y + 6)) { nx *= 2; ny *= 2; } dmsx = nx; dmsy = ny; dmbuf = (unsigned char *) AcquireQuantumMemory(dmsx * dmsy,1); if (dmbuf == (unsigned char *) NULL) { imbuf = (unsigned char *) RelinquishMagickMemory(imbuf); return (MagickFalse); } (void) ResetMagickMemory(dmbuf, background_color_index, dmsx * dmsy); for (y = 0; y < imsy; ++y) { (void) CopyMagickMemory(dmbuf + dmsx * y, imbuf + imsx * y, imsx); } imbuf = (unsigned char *) RelinquishMagickMemory(imbuf); imsx = dmsx; imsy = dmsy; imbuf = dmbuf; } if (color_index > max_color_index) { max_color_index = color_index; } if ((b = *(p++) - '?') == 0) { posision_x += repeat_count; } else { sixel_vertical_mask = 0x01; if (repeat_count <= 1) { for (i = 0; i < 6; i++) { if ((b & sixel_vertical_mask) != 0) { imbuf[imsx * (posision_y + i) + posision_x] = color_index; if (max_x < posision_x) { max_x = posision_x; } if (max_y < (posision_y + i)) { max_y = posision_y + i; } } sixel_vertical_mask <<= 1; } posision_x += 1; } else { /* repeat_count > 1 */ for (i = 0; i < 6; i++) { if ((b & sixel_vertical_mask) != 0) { c = sixel_vertical_mask << 1; for (n = 1; (i + n) < 6; n++) { if ((b & c) == 0) { break; } c <<= 1; } for (y = posision_y + i; y < posision_y + i + n; ++y) { (void) ResetMagickMemory(imbuf + imsx * y + posision_x, color_index, repeat_count); } if (max_x < (posision_x + repeat_count - 1)) { max_x = posision_x + repeat_count - 1; } if (max_y < (posision_y + i + n - 1)) { max_y = posision_y + i + n - 1; } i += (n - 1); sixel_vertical_mask <<= (n - 1); } sixel_vertical_mask <<= 1; } posision_x += repeat_count; } } repeat_count = 1; } else { p++; } } if (++max_x < attributed_ph) { max_x = attributed_ph; } if (++max_y < attributed_pv) { max_y = attributed_pv; } if (imsx > max_x || imsy > max_y) { dmsx = max_x; dmsy = max_y; if ((dmbuf = (unsigned char *) AcquireQuantumMemory(dmsx * dmsy,1)) == NULL) { imbuf = (unsigned char *) RelinquishMagickMemory(imbuf); return (MagickFalse); } for (y = 0; y < dmsy; ++y) { (void) CopyMagickMemory(dmbuf + dmsx * y, imbuf + imsx * y, dmsx); } imbuf = (unsigned char *) RelinquishMagickMemory(imbuf); imsx = dmsx; imsy = dmsy; imbuf = dmbuf; } *pixels = imbuf; *pwidth = imsx; *pheight = imsy; *ncolors = max_color_index + 1; *palette = (unsigned char *) AcquireQuantumMemory(*ncolors,4); for (n = 0; n < (ssize_t) *ncolors; ++n) { (*palette)[n * 4 + 0] = sixel_palet[n] >> 16 & 0xff; (*palette)[n * 4 + 1] = sixel_palet[n] >> 8 & 0xff; (*palette)[n * 4 + 2] = sixel_palet[n] & 0xff; (*palette)[n * 4 + 3] = 0xff; } return(MagickTrue); }
int main(int argc, char **argv) { int i,j,flag,jchan,nchans,ngfcomp=6,nsects,ierror=1 ; int tapering=NON,nh=NDEPTHS,nd=NDISTAS ; long int nerr = 0 ; char stat_file[FSIZE],i_master[FSIZE],path[FSIZE]; char sacfile[FSIZE],itype[2], ori; char *gfcomp[]={"rr","tt","pp","rt","rp","tp"}; char **stats, **nets, **cmps, **locs ; float *stlats,*stlons,*dists,*cmpazs, *azs,*bazs,*xdegs ; double **GFs,*S,*TH,*PH,*x_conv,*tv,*dv ; double *b1,*b2,*a1,*a2,gain,dt=1.; str_quake_params eq; sachdr hdr; /* Set input parameters */ get_params(argc, argv, stat_file, itype, i_master, &eq, &tapering) ; get_cmtf(&eq, 1) ; /* Allocations */ GFs = double_alloc2(10,__LEN_SIG__);/* GFs: Rrr, Rtt, Rpp, Rrt */ TH = double_alloc(__LEN_SIG__) ; /* Radial components */ PH = double_alloc(__LEN_SIG__) ; /* Transverse components */ S = double_alloc(__LEN_SIG__) ; /* work copy */ x_conv = double_alloc((int)__LEN_SIG__) ; eq.vm = double_alloc2p(2) ; eq.vm[1] = double_alloc(6) ; eq.vm[0] = double_alloc(6) ; hdr_init(&hdr) ; /* SAC header allocation */ nsects = (eq.flow > 0.)? eq.filtorder : eq.filtorder/2 ; b1 = double_alloc(nsects) ; b2 = double_alloc(nsects) ; a1 = double_alloc(nsects) ; a2 = double_alloc(nsects) ; tv = double_alloc(nd); /* travel times */ dv = double_alloc(nd); /* distances */ /* Reading CMTSOLUTION and STAT_FILE */ nchans = r_scr_dat_fil_list(stat_file, &stats, &nets, &cmps, &locs, &stlats, &stlons,&cmpazs) ; dists = float_calloc(nchans) ; azs = float_calloc(nchans) ; bazs = float_calloc(nchans) ; xdegs = float_calloc(nchans) ; /* Distance, azimuth, back-azimuth, etc */ distaz(eq.evla, eq.evlo, stlats, stlons, nchans, dists, azs, bazs, xdegs, &nerr) ; /* Set travel time table for depth = dep */ trav_time_init(nh,nd,eq.evdp,dv,tv,&ierror); /* Excitation kernels calculation */ crea_dir(eq.gf_dir) ; flag = 0 ; for(i=0;i<ngfcomp;i++) { printf("**************************************\n"); printf("Computing synthetics for M_%s...\n",gfcomp[i]); strcpy(path,eq.gf_dir) ; strcat(path,"gf_") ; strcat(path,gfcomp[i]) ; crea_dir(path) ; strcat(path,"/") ; for(j=0;j<ngfcomp;j++)/* Inititializing the MT components */ eq.vm[1][j] = 0. ; eq.vm[1][i] = 1. ; for(jchan=0;jchan<nchans;jchan++) /* Computing kernels for MT component #i at each station */ { flag = 0; /* Computing Z, TH, PH */ ori = cmps[jchan][2]; printf("%-5s", stats[jchan]) ; if ( ori == 'Z' ) { fast_synth_only_Z_sub(azs[jchan], bazs[jchan], xdegs[jchan], tv,dv,nd,&eq,&hdr,GFs,S); hdr.cmpaz = 0.; hdr.cmpinc = 0.; } else if ( ori == 'N' || ori == 'E' || ori == '1' || ori == '2' ) { fast_synth_only_Hs_sub(azs[jchan], bazs[jchan], xdegs[jchan],tv,dv,nd,&eq,&hdr,GFs,TH,PH); rotate_traces(TH, PH, bazs[jchan]-cmpazs[jchan], hdr.npts, S) ; /*Rotating TH, PH to H*/ hdr.cmpaz = cmpazs[jchan]; hdr.cmpinc = 90.; } else continue; if (tapering == YES) taper_one_trace(S,&hdr); strcpy(sacfile,path) ; /* Save Raw GF SAC */ strcat(sacfile,stats[jchan]) ; strcat(sacfile,".") ; strcat(sacfile,nets[jchan]) ; strcat(sacfile,".") ; strcat(sacfile,cmps[jchan]) ; strcat(sacfile,".") ; strcat(sacfile,locs[jchan]) ; strcat(sacfile,".SAC") ; save_gf_sac(sacfile,stats[jchan],nets[jchan],cmps[jchan],locs[jchan],&stlats[jchan],&stlons[jchan],&hdr,S) ; conv_by_stf(eq.ts,eq.hd,itype,&hdr,S,x_conv) ;/* Perform convolution */ if (flag == 0) /* Set the butterworth sos (dt must be the same for all stations) */ { flag = 1 ; dt = (double)hdr.delta ; if (eq.flow>0.) bpbu2sos(eq.flow,eq.fhigh,dt,eq.filtorder,&gain,b1,b2,a1,a2); else lpbu2sos(eq.fhigh,dt,eq.filtorder,&gain,b1,b2,a1,a2); } else if (dt != (double)hdr.delta) { fprintf(stderr, "ERROR: non uniform samp. period between sac files, file : %s\n",sacfile); fprintf(stderr, "%f != %f\n", dt, hdr.delta); exit(1); } strcat(sacfile,".sac") ; /* Save SAC after STF convolution */ save_gf_sac(sacfile,stats[jchan],nets[jchan],cmps[jchan],locs[jchan],&stlats[jchan],&stlons[jchan],&hdr,x_conv) ; filter_with_sos(gain,b1,b2,a1,a2,nsects,x_conv,hdr.npts) ; /* Apply sos */ strcat(sacfile,".bp") ; /* Save SAC after bandpass filtering */ save_gf_sac(sacfile,stats[jchan],nets[jchan],cmps[jchan],locs[jchan],&stlats[jchan],&stlons[jchan],&hdr,x_conv) ; } printf("\n"); } /* Freeing memory */ free((void*)b1) ; free((void*)b2) ; free((void*)a1) ; free((void*)a2) ; free((void*)S) ; free((void*)PH); free((void*)TH); free((void*)x_conv); for(i=0; i<10; i++) free((void *)GFs[i]) ; free((void**)GFs) ; free((void*)eq.vm[0]) ; free((void*)eq.vm[1]) ; free((void**)eq.vm) ; free((void*)dists) ; free((void*)azs) ; free((void*)bazs) ; free((void*)xdegs) ; for (i=0;i< nchans;i++) { free((void*)stats[i]) ; free((void*)nets[i]) ; } free((void**)stats) ; free((void**)nets) ; free((void*)stlats) ; free((void*)stlons) ; free((void*)cmpazs) ; if(tapering == YES) { free((void*)tv); free((void*)dv); } printf("\n"); return 0; }
void ps_mat(char *outf,int nmat,t_matrix mat[],t_matrix mat2[], bool bFrame,bool bDiag,bool bFirstDiag, bool bTitle,bool bTitleOnce,bool bYonce,int elegend, real size,real boxx,real boxy,char *m2p,char *m2pout, int mapoffset) { char *libm2p; char buf[256],*legend; t_psdata out; t_psrec psrec,*psr; int W,H; int i,j,x,y,col,leg=0; real x0,y0,xx; real w,h,dw,dh; int nmap1=0,nmap2=0,leg_nmap; t_mapping *map1=NULL,*map2=NULL,*leg_map; bool bMap1,bNextMap1,bDiscrete; libm2p = m2p ? strdup(libfn(m2p)) : m2p; get_params(libm2p,m2pout,&psrec); psr=&psrec; if (psr->X.major <= 0 ) tick_spacing((mat[0].flags & MAT_SPATIAL_X) ? mat[0].nx + 1 : mat[0].nx, mat[0].axis_x, psr->X.offset, 'X', &(psr->X.major), &(psr->X.minor) ); if (psr->X.minor <= 0 ) psr->X.minor = psr->X.major / 2; if (psr->Y.major <= 0) tick_spacing((mat[0].flags & MAT_SPATIAL_Y) ? mat[0].ny + 1 : mat[0].ny, mat[0].axis_y, psr->Y.offset, 'Y', &(psr->Y.major), &(psr->Y.minor) ); if (psr->Y.minor <= 0) psr->Y.minor = psr->Y.major / 2; if (boxx>0) { psr->xboxsize=boxx; psr->yboxsize=boxx; } if (boxy>0) psr->yboxsize=boxy; if (psr->xboxsize==0) { psr->xboxsize = size/mat[0].nx; printf("Set the x-size of the box to %.3f\n",psr->xboxsize); } if (psr->yboxsize==0) { psr->yboxsize = size/mat[0].nx; printf("Set the y-size of the box to %.3f\n",psr->yboxsize); } nmap1=0; for (i=0; (i<nmat); i++) if (mat[i].nmap>nmap1) { nmap1=mat[i].nmap; map1=mat[i].map; leg=i+1; } if (leg!=1) printf("Selected legend of matrix # %d for display\n",leg); if (mat2) { nmap2=0; for (i=0; (i<nmat); i++) if (mat2[i].nmap>nmap2) { nmap2=mat2[i].nmap; map2=mat2[i].map; leg=i+1; } if (leg!=1) printf("Selected legend of matrix # %d for second display\n",leg); } if ( (mat[0].legend[0]==0) && psr->legend ) strcpy(mat[0].legend, psr->leglabel); bTitle = bTitle && mat[nmat-1].title[0]; bTitleOnce = bTitleOnce && mat[nmat-1].title[0]; psr->bTitle = bTitle; psr->bTitleOnce = bTitleOnce; psr->bYonce = bYonce; /* Set up size of box for nice colors */ box_dim(nmat,mat,mat2,psr,elegend,bFrame,&w,&h,&dw,&dh); /* Set up bounding box */ W=w+dw; H=h+dh; /* Start box at */ x0=dw; y0=dh; x = W+psr->xoffs; y = H+psr->yoffs; if (bFrame) { x += 5*DDD; y += 4*DDD; } out=ps_open(outf,0,0,x,y); ps_linewidth(out,psr->linewidth); ps_init_rgb_box(out,psr->xboxsize,psr->yboxsize); ps_init_rgb_nbox(out,psr->xboxsize,psr->yboxsize); ps_translate(out,psr->xoffs,psr->yoffs); if (bFrame) { ps_comment(out,"Here starts the BOX drawing"); draw_boxes(out,x0,y0,w,nmat,mat,psr); } for(i=0; (i<nmat); i++) { if (bTitle || (bTitleOnce && i==nmat-1) ) { /* Print title, if any */ ps_rgb(out,BLACK); ps_strfont(out,psr->titfont,psr->titfontsize); if (!mat2 || (strcmp(mat[i].title,mat2[i].title) == 0)) strcpy(buf,mat[i].title); else sprintf(buf,"%s / %s",mat[i].title,mat2[i].title); ps_ctext(out,x0+w/2,y0+box_height(&(mat[i]),psr)+psr->titfontsize, buf,eXCenter); } sprintf(buf,"Here starts the filling of box #%d",i); ps_comment(out,buf); for(x=0; (x<mat[i].nx); x++) { int nexty; int nextcol; xx=x0+x*psr->xboxsize; ps_moveto(out,xx,y0); y=0; bMap1 = (!mat2 || (x<y || (x==y && bFirstDiag))); if ((bDiag) || (x!=y)) col = mat[i].matrix[x][y]; else col = -1; for(nexty=1; (nexty<=mat[i].ny); nexty++) { bNextMap1 = (!mat2 || (x<nexty || (x==nexty && bFirstDiag))); /* TRUE: upper left -> map1 */ /* FALSE: lower right -> map2 */ if ((nexty==mat[i].ny) || (!bDiag && (x==nexty))) nextcol = -1; else nextcol=mat[i].matrix[x][nexty]; if ( (nexty==mat[i].ny) || (col!=nextcol) || (bMap1!=bNextMap1) ) { if (col >= 0) if (bMap1) ps_rgb_nbox(out,&(mat[i].map[col].rgb),nexty-y); else ps_rgb_nbox(out,&(mat2[i].map[col].rgb),nexty-y); else ps_moverel(out,0,psr->yboxsize); y=nexty; bMap1=bNextMap1; col=nextcol; } } } y0+=box_height(&(mat[i]),psr)+box_dh(psr)+box_dh_top(IS_ONCE,psr); } if (psr->X.lineatzero || psr->Y.lineatzero) { /* reset y0 for first box */ y0=dh; ps_comment(out,"Here starts the zero lines drawing"); draw_zerolines(out,x0,y0,w,nmat,mat,psr); } if (elegend!=elNone) { ps_comment(out,"Now it's legend time!"); ps_linewidth(out,psr->linewidth); if ( mat2==NULL || elegend!=elSecond ) { bDiscrete = mat[0].bDiscrete; legend = mat[0].legend; leg_nmap = nmap1; leg_map = map1; } else { bDiscrete = mat2[0].bDiscrete; legend = mat2[0].legend; leg_nmap = nmap2; leg_map = map2; } if (bDiscrete) leg_discrete(out,psr->legfontsize,DDD,legend, psr->legfontsize,psr->legfont,leg_nmap,leg_map); else { if ( elegend!=elBoth ) leg_continuous(out,x0+w/2,w/2,DDD,legend, psr->legfontsize,psr->legfont,leg_nmap,leg_map, mapoffset); else leg_bicontinuous(out,x0+w/2,w,DDD,mat[0].legend,mat2[0].legend, psr->legfontsize,psr->legfont,nmap1,map1,nmap2,map2); } ps_comment(out,"Were there, dude"); } ps_close(out); }
int main(int argc, char** argv) { unsigned i; struct timeval tv; double sum = 0; double min_time_per_op = -1; double min_of_max = -1; grt_random_init(); int got_params = get_params(); hash_map_init(argc, argv, params[SHARE_POWER]); if (!got_params) { if (grt_id == 0) { fprintf(stderr, "*** USING DEFAULT PARAMETERS ***\n"); } grt_barrier(); } keys = malloc(MY_NUM_OPS * sizeof(grt_word_t)); values = malloc(MY_NUM_OPS * sizeof(grt_word_t)); int nth = 4*grt_distrib_start(params[NUM_OPS])+1; grt_random_nth(grt_distrib_start(nth)); for (i = 0; i < MY_NUM_OPS; ++i) { keys[i] = RAND_MAX * grt_random_next(); values[i] = RAND_MAX * grt_random_next(); } grt_barrier(); if (grt_id == 0) { printf("User-specified parameters:\n"); for (i = 0; i < NUM_PARAMS; ++i) { const char *name = param_names[i]; unsigned param = params[i]; printf(" %s=", name); if (i == ON_PTHREAD) printf((param == GRT_TRUE) ? "yes" : "no"); else printf("%u", param); printf("\n"); } printf(" grt_num_procs=%u\n", grt_num_procs); } grt_barrier(); times = (grt_word_t*) grt_all_alloc(0, grt_num_procs * sizeof(grt_word_t)); for (i = 0; i < params[NUM_RUNS]; ++i) { if (grt_id == 0) { printf("\nRUN NUMBER %u\n\n", i); fflush(stdout); } BARRIER(); run(); if (grt_id == 0) { sum += time_per_op; if (min_time_per_op == -1 || time_per_op < min_time_per_op) min_time_per_op = time_per_op; if (min_of_max == -1 || max_time < min_of_max) min_of_max = max_time; } } BARRIER(); if (grt_id == 0) { printf("\nSUMMARY RESULTS\n\n"); printf("average time per operation=%f us\n", sum / params[NUM_RUNS]); printf("min time per op=%f us\n", min_time_per_op); printf("min of max=%f us\n", min_of_max); } hash_map_exit(0); }
/* * ndmpd_file_history_dir * * Generate file history directory information posts */ int ndmpd_file_history_dir(lbr_fhlog_call_backs_t *cbp, char *dir, struct stat64 *stp) { char nm[PATH_MAX+1]; int nml; int err; ulong_t ino, pino; ulong_t pos; ndmp_lbr_params_t *nlp; ndmpd_module_params_t *params; DIR *dirp; char dirpath[PATH_MAX]; if (!cbp) { err = -1; syslog(LOG_DEBUG, "cbp is NULL"); } else if (!cbp->fh_cookie) { err = -1; syslog(LOG_DEBUG, "cookie is NULL"); } else if (!dir) { err = -1; syslog(LOG_DEBUG, "dir is NULL"); } else if (!stp) { err = -1; syslog(LOG_DEBUG, "stp is NULL"); } if (!(nlp = ndmp_get_nlp(cbp->fh_cookie))) { err = -1; syslog(LOG_DEBUG, "nlp is NULL"); } else err = 0; if (err != 0) return (0); syslog(LOG_DEBUG, "dir: \"%s\"", dir); if (!fh_requested(cbp->fh_cookie)) return (0); /* * Veritas net_backup accepts only 2 as the inode number of the backup * root directory. The other way compares the path against the * backup path which is slower. */ if (stp->st_ino == nlp->nlp_bkdirino) pino = ROOT_INODE; else pino = stp->st_ino; /* * There is nothing below this directory to be backed up. * If there was, the bit for this directory would have * been set. Backup root directory is exception. We * always send the dir file history records of it. */ if (pino != ROOT_INODE && !dbm_getone(nlp->nlp_bkmap, (u_longlong_t)stp->st_ino)) { syslog(LOG_DEBUG, "nothing below here"); return (0); } params = get_params(cbp->fh_cookie); if (params == NULL || params->mp_file_history_dir_func == NULL) { return (0); } pos = 0; err = 0; dirp = opendir(dir); if (dirp == NULL) return (0); do { nml = PATH_MAX; err = dp_readdir(dirp, &pos, nm, &nml, &ino); if (err != 0) { syslog(LOG_DEBUG, "%d reading pos %u dir \"%s\"", err, pos, dir); break; } if (nml == 0) break; nm[nml] = '\0'; if (pino == ROOT_INODE) { if (rootfs_dot_or_dotdot(nm)) ino = ROOT_INODE; } else if (ino == nlp->nlp_bkdirino && IS_DOTDOT(nm)) { syslog(LOG_DEBUG, "nm(%s): %lu", nm, ino); ino = ROOT_INODE; } if (!dbm_getone(nlp->nlp_bkmap, (u_longlong_t)ino)) continue; err = (*params->mp_file_history_dir_func)(cbp->fh_cookie, nm, ino, pino); if (err < 0) { syslog(LOG_ERR, "\"%s/%s\": %d", dir, nm, err); break; } /* * This is a requirement by some DMA's (net_vault) that during * the incremental backup, the node info should also be sent * along with the dir info for all directories leading to a * backed up file. */ if (ndmp_fhinode) { struct stat64 ret_attr; (void) strlcpy(dirpath, dir, PATH_MAX); (void) strlcat(dirpath, "/", PATH_MAX); (void) strlcat(dirpath, nm, PATH_MAX); err = stat64(dirpath, &ret_attr); if (err != 0) { syslog(LOG_ERR, "Error looking up %s failed", nm); break; } if (S_ISDIR(ret_attr.st_mode)) { err = (*params->mp_file_history_node_func)(cbp-> fh_cookie, ino, &ret_attr, 0); if (err < 0) { syslog(LOG_DEBUG, "\"%s/\": %d", dir, err); break; } } } } while (err == 0); (void) closedir(dirp); return (err); }
int main(int argc, char *argv[]) { int i, j, ns, flag, flagr, ierror, nsects, nh=NDEPTHS, nd=NDISTAS ; long int nerr ; double **GFs,*S,*TH,*PH,*x_conv ; double *b1, *b2, *a1, *a2, gain, dt=1.0 ; double *tv, *dv ; float dist,az,baz,xdeg; char i_master[FSIZE], i_wpfilname[FSIZE], datafile[FSIZE], buf[200] ; char o_dir[FSIZE], *o_file,stnm[9],netwk[9],cmpnm[9], khole[9]; char stacmp[]= {'Z','N','E','1','2'} ; char itype[2]="l", ori; str_quake_params eq ; sachdr hd_data, hd_synt ; FILE *i_wp ; /* Input params */ if (argc < 5) { fprintf(stderr,"Error input params \n"); fprintf(stderr,"Syntax : %s i_master cmtfile i_wpinversion o_direct [stftype]\n", argv[0]); fprintf(stderr,"stftype (optionnal) can be either:\n g (gaussian),\n q (parabolic),\n l (triangle,\n default),\n b(boxcar) or\n c (cosine)\n"); exit(1); } strcpy( i_master, argv[1]) ; strcpy(i_wpfilname, argv[3]) ; strcpy( o_dir, argv[4]) ; get_params(i_master, &eq) ; strcpy( eq.cmtfile, argv[2]) ; if (argc==6) { if (strlen(argv[5])==1) strcpy(itype,argv[5]); else { fprintf(stderr,"Error input params \n"); fprintf(stderr,"Syntax : %s i_master cmtfile i_wpinversion o_direct [stftype]\n", argv[0]); fprintf(stderr,"stftype (optionnal) can be either:\n g (gaussian),\n q (parabolic),\n l (triangle,\n default),\n b(boxcar) or\n c (cosine)\n"); exit(1); } } /* Allocates memory */ eq.vm = double_alloc2p(2) ; eq.vm[0] = double_calloc(6) ; eq.vm[1] = double_calloc(6) ; GFs = double_alloc2(10,__LEN_SIG__) ;/* GFs: Rrr, Rtt, Rpp, Rrt */ S = double_alloc(__LEN_SIG__) ;/* Vertical components */ TH = double_alloc(__LEN_SIG__) ;/* Radial components */ PH = double_alloc(__LEN_SIG__) ;/* Transverse components */ x_conv = double_alloc(__LEN_SIG__) ; hdr_init(&hd_data) ; hdr_init(&hd_synt) ; nsects = (eq.flow > 0.)? eq.filtorder : eq.filtorder/2 ; b1 = double_alloc(nsects) ; b2 = double_alloc(nsects) ; a1 = double_alloc(nsects) ; a2 = double_alloc(nsects) ; tv = double_alloc(nd); /* travel times */ dv = double_alloc(nd); /* distances */ /* Read CMTFILE */ get_cmtf(&eq,2) ; /* Set travel time table for depth = dep */ ierror = 1 ; trav_time_init(nh,nd,eq.evdp,dv,tv,&ierror) ; /* Read list of data files */ flag = 0 ; i_wp = openfile_rt(i_wpfilname, &ns); for(i=0; i<ns; i++) { flagr = fscanf (i_wp, "%s", datafile) ; fgets(buf,200,i_wp); /* end of line */ check_scan(1, flagr, i_wpfilname, i_wp) ; rhdrsac(datafile, &hd_data, &ierror) ; /* Calculate azimuths, back-azimuths */ dist = 0. ; az = 0. ; baz = 0. ; xdeg = 0. ; distaz(eq.evla,eq.evlo,&hd_data.stla,&hd_data.stlo,1,&dist,&az,&baz,&xdeg,&nerr) ; ori = hd_data.kcmpnm[2]; if ( ori == 'Z' ) fast_synth_only_Z_sub(az,baz,xdeg, tv,dv,nd,&eq,&hd_synt,GFs,S); else if ( ori == 'N' || ori == 'E' || ori == '1' || ori == '2' ) { fast_synth_only_Hs_sub(az,baz,xdeg,tv,dv,nd,&eq,&hd_synt,GFs,TH,PH); rotate_traces(TH, PH, baz-hd_data.cmpaz,hd_synt.npts, S) ; /*Rotating TH, PH to H*/ } else continue; sscanf(hd_data.kstnm,"%s",stnm); sscanf(hd_data.knetwk,"%s",netwk); sscanf(hd_data.kcmpnm,"%s",cmpnm); strcpy(khole, hd_data.khole); // It can contain blanks for(j=0; j<5; j++) { if (cmpnm[2] == stacmp[j]) break; } if (j==5) { fprintf(stderr,"*** ERROR: Unknownk component %s for sta %s\n",cmpnm,stnm) ; fprintf(stderr," -> Exiting\n") ; fflush(stderr); exit(1); } conv_by_stf(eq.ts,eq.hd,itype,&hd_synt,S,x_conv) ;/* Perform convolution */ strcpy(hd_synt.kstnm,hd_data.kstnm) ; strcpy(hd_synt.kcmpnm,hd_data.kcmpnm) ; strcpy(hd_synt.knetwk,hd_data.knetwk) ; hd_synt.stla = hd_data.stla ; hd_synt.stlo = hd_data.stlo ; hd_synt.evla = eq.pde_evla; hd_synt.evlo = eq.pde_evlo; hd_synt.evdp = eq.pde_evdp; /* Write output file 1 */ o_file = get_gf_filename(o_dir,stnm,netwk,cmpnm,khole,".complete_synth.sac") ; wsac(o_file,&hd_synt,x_conv); free((void*)o_file) ; if (flag == 0) /* Set the butterworth sos (dt must be the same for all stations) */ { flag = 1 ; dt = (double)hd_data.delta; if (eq.flow>0.) bpbu2sos(eq.flow,eq.fhigh,dt,eq.filtorder,&gain,b1,b2,a1,a2); else lpbu2sos(eq.fhigh,dt,eq.filtorder,&gain,b1,b2,a1,a2); } else if ((int)(dt*1000+0.5) != (int)((double)hd_data.delta*1000+0.5)) { fprintf(stderr, "ERROR: non uniform samp. period between sac files, file : %s\n",datafile); exit(1); } filter_with_sos(gain,b1,b2,a1,a2,nsects,x_conv,hd_synt.npts) ; /* Apply sos */ /* Write output file 2 */ o_file = get_gf_filename(o_dir,stnm,netwk,cmpnm,khole,".complete_synth.bp.sac") ; printf("Writing sac file : %s\n",o_file) ; wsac(o_file,&hd_synt,x_conv); free((void*)o_file) ; } fclose(i_wp); free((void*)S); free((void*)TH); free((void*)PH); for(j=0; j<10; j++) free((void*)GFs[j]); free((void**)GFs); free((void*)x_conv); free((void*)b1); free((void*)b2); free((void*)a1); free((void*)a2); return 0; }
int main(int argc, char **argv) { sg_log_init("libstatgrab-test", "SGTEST_LOG_PROPERTIES", argc ? argv[0] : NULL); sg_init(1); if( 0 != get_params( opt_def, argc, argv ) ) { help(argv[0]); return 1; } if( opt_def[OPT_HLP].optarg.b ) { help(argv[0]); return 0; } else if( opt_def[OPT_LIST].optarg.b ) { print_testable_functions(0); return 0; } else if( opt_def[OPT_RUN].optarg.str ) { unsigned long numthreads, i; size_t *test_routines = NULL, nfuncs, ok; struct statgrab_testfuncs *sg_testfuncs = get_testable_functions(&nfuncs); size_t entries = funcnames_to_indices(opt_def[OPT_RUN].optarg.str, &test_routines, 0); pthread_t *threadid = NULL; int rc, errors = 0; if( 0 == entries ) { die( ESRCH, "no functions to test" ); return 255; } if( -1 != opt_def[OPT_NTHREADS].optarg.s ) { numthreads = opt_def[OPT_NTHREADS].optarg.u; if( numthreads < entries ) { die( ERANGE, "%s %s - to small number for thread count", argv[0], argv[2] ); } } else if( opt_def[OPT_MTHREADS].optarg.u > 1 ) { numthreads = entries * opt_def[OPT_MTHREADS].optarg.u; } else { numthreads = entries; } if( NULL == ( threadid = calloc( sizeof(threadid[0]), numthreads ) ) ) die( ENOMEM, "%s", argv[0] ); rc = pthread_mutex_lock(&mutex); prove_libcall("pthread_mutex_lock", rc); TRACE_LOG_FMT( "multi_threaded", "create %lu threads", numthreads ); for( i = 0; i < numthreads; ++i ) { mark_func(test_routines[i % entries]); rc = pthread_create( &threadid[i], NULL, threadfunc, &test_routines[i % entries] ); prove_libcall("pthread_create", rc); } rc = pthread_mutex_unlock(&mutex); prove_libcall("pthread_mutex_unlock", rc); while( test_counter < numthreads ) sched_yield(); rc = pthread_mutex_lock(&mutex); prove_libcall("pthread_mutex_lock", rc); /* The condition has occured. Set the flag and wake up any waiting threads */ conditionMet = 1; TRACE_LOG( "multi_threaded", "Wake up all waiting threads..." ); rc = pthread_cond_broadcast(&cond); prove_libcall("pthread_cond_broadcast", rc); rc = pthread_mutex_unlock(&mutex); prove_libcall("pthread_mutex_unlock", rc); TRACE_LOG( "multi_threaded", "Wait for threads and cleanup" ); do { struct timespec ts = { 1, 0 }; struct timeval tv; gettimeofday(&tv, NULL); ts.tv_sec += tv.tv_sec; rc = pthread_mutex_lock(&mutex); prove_libcall("pthread_mutex_lock", rc); pthread_cond_timedwait(&cond, &mutex, &ts); prove_libcall("pthread_cond_timedwait", rc); ok = report_testable_functions(0); rc = pthread_mutex_unlock(&mutex); prove_libcall("pthread_mutex_unlock", rc); if( ok != nfuncs ) printf( "---------------\n" ); fflush(stdout); } while( ok != nfuncs ); for (i=0; i<numthreads; ++i) { rc = pthread_join(threadid[i], NULL); prove_libcall("pthread_join", rc); } pthread_cond_destroy(&cond); pthread_mutex_destroy(&mutex); for( i = 0; i < nfuncs; ++i ) errors += sg_testfuncs[i].needed - sg_testfuncs[i].succeeded; TRACE_LOG_FMT( "multi_threaded", "Main completed with test_counter = %lu", test_counter ); return errors; } help(argv[0]); return 1; }
lbool check_sat_core(unsigned num_assumptions, expr * const * assumptions) override { m_solver->updt_params(get_params()); return m_solver->check_sat(num_assumptions, assumptions); }