void painth(int counts[], int maxlen){ printf("\nHorizontal histogram:\n"); int peak = getpeak(counts, maxlen); int i,j; for(i=0;i<maxlen;i++) { int len = counts[i] * 20 / peak + 1; char bar[len]; for(j=0;j<len-1;j++) { bar[j] = '*'; } bar[j] = '\0'; if(i < maxlen - 1) printf("%2d: %s %2d\n",i+1,bar,counts[i]); else printf(">=%2d: %s %2d\n",i+1,bar,counts[i]); } }
void paintv(int counts[], int maxlen) { printf("\nVertical histogram:\n"); int i,j,h = 20; int peak = getpeak(counts, maxlen); int bars[maxlen]; for(i =0;i<maxlen;i++) bars[i] = counts[i] * h / peak; for(i=0;i<=h;i++) { for(j=0;j<maxlen;j++) { if(bars[j] == (h - i)) { printf("%-5d", counts[j]); } else if(bars[j] > (h - i)){ printf("%-5c",'*'); } else{ printf("%-5c",' '); } } printf("\n"); } for (i = 0; i < maxlen; i++) { printf("====="); } printf("\n"); for(i = 0;i< maxlen;i++) { if(i < maxlen - 1) printf("%-5d",i+1); else printf(">=%-5d",i+1); } }
int main (int argc, char **argv) { #ifdef VSG_HAVE_MPI VsgPRTreeParallelConfig pconfig = {{NULL,}}; #endif VsgVector3d lbound = {-TR, -TR, -TR}; VsgVector3d ubound = {TR, TR, TR}; VsgPRTree3d *prtree; AranSolver3d *solver; int ret = 0; GTimer *timer = NULL; #ifdef VSG_HAVE_MPI MPI_Init (&argc, &argv); MPI_Comm_size (MPI_COMM_WORLD, &sz); MPI_Comm_rank (MPI_COMM_WORLD, &rk); #endif aran_init(); parse_args (argc, argv); #ifdef VSG_HAVE_MPI pconfig.communicator = MPI_COMM_WORLD; pconfig.point = point_accum_vtable; aran_development3d_vtable_init (&pconfig.node_data, 0, order); #endif /* points = g_ptr_array_new (); */ if (check) { _cp_size = MAX (np, 128); check_points = g_malloc0 (_cp_size * sizeof (PointAccum)); } prtree = vsg_prtree3d_new_full (&lbound, &ubound, (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc, (VsgPoint3dDistFunc) vsg_vector3d_dist, (VsgRegion3dLocFunc) NULL, maxbox); solver = aran_solver3d_new (prtree, ARAN_TYPE_DEVELOPMENT3D, aran_development3d_new (0, order), (AranZeroFunc) aran_development3d_set_zero); #ifdef VSG_HAVE_MPI aran_solver3d_set_parallel (solver, &pconfig); #endif if (virtual_maxbox != 0) aran_solver3d_set_nf_isleaf (solver, _nf_isleaf_virtual_maxbox, &virtual_maxbox); aran_solver3d_set_functions (solver, (AranParticle2ParticleFunc3d) p2p, (AranParticle2MultipoleFunc3d) p2m, m2m, m2l, l2l, (AranLocal2ParticleFunc3d) l2p); if (semifar_threshold < G_MAXUINT) { aran_solver3d_set_functions_full (solver, (AranParticle2ParticleFunc3d) p2p, (AranParticle2MultipoleFunc3d) p2m, m2m, m2l, l2l, (AranLocal2ParticleFunc3d) l2p, (AranParticle2LocalFunc3d) p2l, (AranMultipole2ParticleFunc3d) m2p, semifar_threshold); if (semifar_threshold == 0) { PointAccum p1 = {{0.1, 0.1, 0.1}, 0.1, {0., 0., 0.}, 0}; PointAccum p2 = {{-0.1, -0.1, -0.1}, 0.1, {0., 0., 0.}, 1}; /* compute operators timings to be able to compute optimal solver parameters */ aran_solver3d_profile_operators (solver, (AranParticleInitFunc3d) point_accum_clear_accum, &p1, &p2); /* alternatively, we could get timings from profile databases */ /* aran_profile_db_read_file ("./profiledb-newtonfield3.ini", NULL); */ /* aran_solver3d_db_profile_operators (solver, (gdouble) order); */ } } if (_hilbert) { /* configure for hilbert curve order traversal */ aran_solver3d_set_children_order_hilbert (solver); } if (_verbose) { g_printerr ("%d : fill begin\n", rk); g_printerr ("%d : memory peak1 count = %u\n", rk, getpeak(0)); #ifdef VSG_HAVE_MPI MPI_Barrier (MPI_COMM_WORLD); #endif timer = g_timer_new (); } _fill (solver); if (_verbose) { g_printerr ("%d : fill elapsed=%f seconds\n", rk, g_timer_elapsed (timer, NULL)); g_printerr ("%d : tree depth count = %d\n", rk, aran_solver3d_depth (solver)); g_printerr ("%d : particle count=%d\n", rk, aran_solver3d_point_count (solver)); g_timer_destroy (timer); /* g_mem_profile(); */ } if (_verbose) { g_printerr ("%d : solve begin\n", rk); g_printerr ("%d : memory peak2 count = %u\n", rk, getpeak(0)); #ifdef VSG_HAVE_MPI MPI_Barrier (MPI_COMM_WORLD); #endif timer = g_timer_new (); } aran_solver3d_solve (solver); if (_verbose) { #ifdef VSG_HAVE_MPI MPI_Barrier (MPI_COMM_WORLD); #endif g_printerr ("%d : solve ok elapsed=%f seconds\n", rk, g_timer_elapsed (timer, NULL)); g_printerr ("%d : memory peak3 count = %u\n", rk, getpeak(0)); g_timer_destroy (timer); { glong zero_count, p2p_count, p2m_count, m2m_count; glong m2l_count, l2l_count, l2p_count, p2l_count, m2p_count; glong p2p_remote_count, m2l_remote_count; aran_solver3d_get_stats (solver, &zero_count, &p2p_count, &p2m_count, &m2m_count, &m2l_count, &l2l_count, &l2p_count, &p2l_count, &m2p_count, &p2p_remote_count, &m2l_remote_count); g_printerr ("%d : zero count=%ld\n", rk, zero_count); g_printerr ("%d : p2p count=%ld\n", rk, p2p_count); g_printerr ("%d : p2p remote count=%ld\n", rk, p2p_remote_count); g_printerr ("%d : p2m count=%ld\n", rk, p2m_count); g_printerr ("%d : m2m count=%ld\n", rk, m2m_count); g_printerr ("%d : m2l count=%ld\n", rk, m2l_count); g_printerr ("%d : m2l remote count=%ld\n", rk, m2l_remote_count); g_printerr ("%d : l2l count=%ld\n", rk, l2l_count); g_printerr ("%d : l2p count=%ld\n", rk, l2p_count); g_printerr ("%d : p2l count=%ld\n", rk, p2l_count); g_printerr ("%d : m2p count=%ld\n", rk, m2p_count); } } if (_write) { gchar fn[1024]; FILE *f; g_sprintf (fn, "tree%03d.txt", rk); f = fopen (fn, "w"); vsg_prtree3d_write (prtree, f); fclose (f); _tree_write (prtree, "solv"); _vtp_tree_write (solver, "solv"); } if (_save_fma_filename != NULL) { FILE *file = fopen (_save_fma_filename, "w"); aran_solver3d_write_fma (solver, file); fclose (file); } if (check) { guint64 i, j; if (sz == 1) { for (i=0; i<np; i ++) { PointAccum *pi = &check_points[i]; for (j=0; j<np; j ++) { if (j != i) { PointAccum *pj = &check_points[j]; p2p_one_way (pi, pj); } } } } else check_parallel_points (solver); aran_solver3d_foreach_point (solver, (GFunc) check_point_field, &ret); if (_verbose) g_printerr ("%d : max err = %e\n", rk, maxerr); g_free (check_points); } aran_solver3d_free (solver); #ifdef VSG_HAVE_MPI aran_development3d_vtable_clear (&pconfig.node_data); #endif /* g_ptr_array_free (points, TRUE); */ if (_load_file != NULL) g_free (_load_file); #ifdef VSG_HAVE_MPI MPI_Finalize (); #endif return ret; }
int main(int ac,char **av) { struct statdata head1; float *s1, vref, vsite, vpga; float *ampf; int nt_p2; float tap_per = TAP_PERC; float pga = -1.0; float fmin = 0.1; float fmax = 15.0; float flowcap = 0.0; /* ampf for f<flowcap set equal to ampf[f=flowcap], (caps low-freq amplification level) */ char infile[128]; char outfile[128]; char model[128]; int inbin = 0; int outbin = 0; float fmidbot = 0.2; /* bottom-end of middle frequency range */ float fmid = 1.0; /* center of middle frequency range */ float fhigh = 3.333; /* center of high frequency range */ float fhightop = 10.0; /* top-end of high frequency range */ /* sprintf(model,"borcherdt"); */ sprintf(model,"cb2014"); setpar(ac,av); mstpar("infile","s",infile); mstpar("outfile","s",outfile); mstpar("vref","f",&vref); mstpar("vsite","f",&vsite); getpar("model","s",model); getpar("pga","f",&pga); vpga = vref; getpar("vpga","f",&vpga); getpar("flowcap","f",&flowcap); getpar("tap_per","f",&tap_per); getpar("fmin","f",&fmin); getpar("fmidbot","f",&fmidbot); getpar("fmid","f",&fmid); getpar("fhigh","f",&fhigh); getpar("fhightop","f",&fhightop); getpar("fmax","f",&fmax); getpar("inbin","d",&inbin); getpar("outbin","d",&outbin); endpar(); if(strncmp(model,"borcherdt",9) != 0 && strncmp(model,"cb2008",6) != 0 && strncmp(model,"bssa2014",6) != 0) sprintf(model,"cb2014"); s1 = NULL; s1 = read_wccseis(infile,&head1,s1,inbin); nt_p2 = getnt_p2(head1.nt); s1 = (float *) check_realloc (s1,nt_p2*size_float); ampf = (float *) check_malloc ((nt_p2/2)*size_float); if(pga < 0.0) getpeak(s1,head1.nt,&pga); else fprintf(stderr,"*** External PGA used: "); fprintf(stderr,"pga= %13.5e\n",pga); taper_norm(s1,&head1.dt,head1.nt,&tap_per); zero(s1+head1.nt,(nt_p2)-head1.nt); forfft((struct complex *)s1,nt_p2,-1); if(strncmp(model,"cb2014",6) == 0) cb2014_ampf(ampf,&head1.dt,nt_p2,&vref,&vsite,&vpga,&pga,&fmin,&fmidbot,&fmid,&fhigh,&fhightop,&fmax,&flowcap); else if(strncmp(model,"bssa2014",8) == 0) bssa2014_ampf(ampf,&head1.dt,nt_p2,&vref,&vsite,&vpga,&pga,&fmin,&fmidbot,&fmid,&fhigh,&fhightop,&fmax,&flowcap); else if(strncmp(model,"cb2008",6) == 0) cb2008_ampf(ampf,&head1.dt,nt_p2,&vref,&vsite,&vpga,&pga,&fmin,&fmidbot,&fmid,&fhigh,&fhightop,&fmax,&flowcap); else borch_ampf(ampf,&head1.dt,nt_p2,&vref,&vsite,&pga,&fmin,&fmidbot,&fmid,&fhigh,&fhightop,&fmax); ampfac((struct complex *)s1,ampf,nt_p2); invfft((struct complex *)s1,nt_p2,1); norm(s1,&head1.dt,nt_p2); write_wccseis(outfile,&head1,s1,outbin); }