static gpointer setup_remove_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) { Options *o = setup_func(i, doc, node); o->add = FALSE; return o; }
/************************************************************************** Load ai module from file. **************************************************************************/ bool load_ai_module(const char *modname) { struct ai_type *ai = ai_type_alloc(); bool setup_success; lt_dlhandle handle; bool (*setup_func)(struct ai_type *ai); const char *(*capstr_func)(void); const char *capstr; char buffer[2048]; char filename[1024]; if (ai == NULL) { return FALSE; } init_ai(ai); fc_snprintf(filename, sizeof(filename), "fc_ai_%s", modname); fc_snprintf(buffer, sizeof(buffer), "%s", filename); handle = lt_dlopenext(buffer); if (handle == NULL) { log_error(_("Cannot open AI module %s (%s)"), filename, fc_module_error()); return FALSE; } fc_snprintf(buffer, sizeof(buffer), "%s_capstr", filename); capstr_func = lt_dlsym(handle, buffer); if (capstr_func == NULL) { log_error(_("Cannot find capstr function from ai module %s (%s)"), filename, fc_module_error()); return FALSE; } capstr = capstr_func(); if (strcmp(FC_AI_MOD_CAPSTR, capstr)) { log_error(_("Incompatible ai module %s:"), filename); log_error(_(" Module options: %s"), capstr); log_error(_(" Supported options: %s"), FC_AI_MOD_CAPSTR); return FALSE; } fc_snprintf(buffer, sizeof(buffer), "%s_setup", filename); setup_func = lt_dlsym(handle, buffer); if (setup_func == NULL) { log_error(_("Cannot find setup function from ai module %s (%s)"), filename, fc_module_error()); return FALSE; } setup_success = setup_func(ai); if (!setup_success) { log_error(_("Setup of ai module %s failed."), filename); return FALSE; } return TRUE; }
/* Do smoothness scaling check & return results */ static double do_stest( int verb, /* Verbosity */ int di, /* Dimensions */ int its, /* Number of function tests */ int res /* RSPL grid resolution */ ) { funcp fp; /* Function parameters */ DCOUNT(gc, MXDIDO, di, 1, 1, res-1); int it; double atse = 0.0; /* Make repeatable by setting random seed before a test set. */ rand32(0x12345678); for (it = 0; it < its; it++) { double tse; setup_func(&fp, di); /* New function */ DC_INIT(gc) tse = 0.0; for (; !DC_DONE(gc);) { double g[MXDI]; int e, k; double y1, y2, y3; double del; for (e = 0; e < di; e++) g[e] = gc[e]/(res-1.0); y2 = lookup_func(&fp, g); del = 1.0/(res-1.0); for (k = 0 ; k < di; k++) { double err; g[k] -= del; y1 = lookup_func(&fp, g); g[k] += 2.0 * del; y3 = lookup_func(&fp, g); g[k] -= del; err = 0.5 * (y3 + y1) - y2; tse += err * err; } DC_INC(gc); } /* Apply adjustments and corrections */ tse *= pow((res-1.0), 4.0); /* Aprox. geometric resolution factor */ tse /= pow((res-2.0),(double)di); /* Average squared non-smoothness */ if (verb) printf("smf for it %d = %f\n",it,tse); atse += tse; } return atse/(double)its; }
static gpointer setup_shrink_func(xmlNodePtr node) { Options *o; o = setup_func(node); o->shrink = TRUE; o->fill = FALSE; return o; }
void smp_rendezvous_cpus(cpumask_t map, void (* setup_func)(void *), void (* action_func)(void *), void (* teardown_func)(void *), void *arg) { int i, ncpus = 0; if (!smp_started) { if (setup_func != NULL) setup_func(arg); if (action_func != NULL) action_func(arg); if (teardown_func != NULL) teardown_func(arg); return; } CPU_FOREACH(i) { if (((1 << i) & map) != 0) ncpus++; } if (ncpus == 0) panic("ncpus is 0 with map=0x%x", map); /* obtain rendezvous lock */ mtx_lock_spin(&smp_ipi_mtx); /* set static function pointers */ smp_rv_ncpus = ncpus; smp_rv_setup_func = setup_func; smp_rv_action_func = action_func; smp_rv_teardown_func = teardown_func; smp_rv_func_arg = arg; smp_rv_waiters[1] = 0; smp_rv_waiters[2] = 0; atomic_store_rel_int(&smp_rv_waiters[0], 0); /* signal other processors, which will enter the IPI with interrupts off */ ipi_selected(map & ~(1 << curcpu), IPI_RENDEZVOUS); /* Check if the current CPU is in the map */ if ((map & (1 << curcpu)) != 0) smp_rendezvous_action(); if (teardown_func == smp_no_rendevous_barrier) while (atomic_load_acq_int(&smp_rv_waiters[2]) < ncpus) cpu_spinwait(); /* release lock */ mtx_unlock_spin(&smp_ipi_mtx); }
void smp_rendezvous(void (*setup_func)(void *), void (*action_func)(void *), void (*teardown_func)(void *), void *arg) { if (setup_func != NULL) setup_func(arg); if (action_func != NULL) action_func(arg); if (teardown_func != NULL) teardown_func(arg); }
void smp_rendezvous(void (*setup_func)(void *), void (*action_func)(void *), void (*teardown_func)(void *), void *arg) { /* Look comments in the smp_rendezvous_cpus() case. */ spinlock_enter(); if (setup_func != NULL) setup_func(arg); if (action_func != NULL) action_func(arg); if (teardown_func != NULL) teardown_func(arg); spinlock_exit(); }
void smp_rendezvous_cpus(cpuset_t map, void (*setup_func)(void *), void (*action_func)(void *), void (*teardown_func)(void *), void *arg) { /* * In the !SMP case we just need to ensure the same initial conditions * as the SMP case. */ spinlock_enter(); if (setup_func != NULL) setup_func(arg); if (action_func != NULL) action_func(arg); if (teardown_func != NULL) teardown_func(arg); spinlock_exit(); }
void smp_rendezvous_cpus(cpuset_t map, void (* setup_func)(void *), void (* action_func)(void *), void (* teardown_func)(void *), void *arg) { int curcpumap, i, ncpus = 0; /* Look comments in the !SMP case. */ if (!smp_started) { spinlock_enter(); if (setup_func != NULL) setup_func(arg); if (action_func != NULL) action_func(arg); if (teardown_func != NULL) teardown_func(arg); spinlock_exit(); return; } CPU_FOREACH(i) { if (CPU_ISSET(i, &map)) ncpus++; } if (ncpus == 0) panic("ncpus is 0 with non-zero map"); mtx_lock_spin(&smp_ipi_mtx); /* Pass rendezvous parameters via global variables. */ smp_rv_ncpus = ncpus; smp_rv_setup_func = setup_func; smp_rv_action_func = action_func; smp_rv_teardown_func = teardown_func; smp_rv_func_arg = arg; smp_rv_waiters[1] = 0; smp_rv_waiters[2] = 0; smp_rv_waiters[3] = 0; atomic_store_rel_int(&smp_rv_waiters[0], 0); /* * Signal other processors, which will enter the IPI with * interrupts off. */ curcpumap = CPU_ISSET(curcpu, &map); CPU_CLR(curcpu, &map); ipi_selected(map, IPI_RENDEZVOUS); /* Check if the current CPU is in the map */ if (curcpumap != 0) smp_rendezvous_action(); /* * Ensure that the master CPU waits for all the other * CPUs to finish the rendezvous, so that smp_rv_* * pseudo-structure and the arg are guaranteed to not * be in use. */ while (atomic_load_acq_int(&smp_rv_waiters[3]) < ncpus) cpu_spinwait(); mtx_unlock_spin(&smp_ipi_mtx); }
/* Do one set of tests and return the results */ static void do_test( double *trmse, /* RETURN total RMS error */ double *tmaxe, /* RETURN total maximum error */ double *tavge, /* RETURN total average error */ int verb, /* Verbosity */ int plot, /* Plot graphs */ int di, /* Dimensions */ int its, /* Number of function tests */ int res, /* RSPL grid resolution */ int ntps, /* Number of sample points */ double noise, /* Sample point noise volume (total = 4 x average deviation) */ int unif, /* NZ if uniform rather than standard deistribution noise */ double smooth, /* Smoothness to test, +ve for extra, -ve for underlying */ int autosm, /* Use auto smoothing */ int seed /* Random seed value offset */ ) { funcp fp; /* Function parameters */ sobol *so; /* Sobol sequence generator */ co *tps = NULL; rspl *rss; /* Multi-resolution regularized spline structure */ datai low,high; double avgdev[MXDO]; int gres[MXDI]; int i, j, it; int flags = RSPL_NOFLAGS; if (autosm) flags |= RSPL_AUTOSMOOTH; *trmse = 0.0; *tmaxe = 0.0; *tavge = 0.0; for (j = 0; j < di; j++) { low[j] = 0.0; high[j] = 1.0; gres[j] = res; } if ((so = new_sobol(di)) == NULL) error("Creating sobol sequence generator failed"); for (it = 0; it < its; it++) { double rmse, avge, maxe; double tnoise = 0.0; /* Make repeatable by setting random seed before a test set. */ rand32(0x12345678 + seed + 0x1000 * it); /* New function */ setup_func(&fp, di); /* Create the object */ rss = new_rspl(RSPL_NOFLAGS,di, 1); /* Create the list of sampling points */ if ((tps = (co *)malloc(ntps * sizeof(co))) == NULL) error ("malloc failed"); so->reset(so); if (verb) printf("Generating the sample points\n"); for (i = 0; i < ntps; i++) { double out, n; so->next(so, tps[i].p); out = lookup_func(&fp, tps[i].p); if (unif) n = d_rand(-0.5 * noise, 0.5 * noise); else n = noise * 0.25 * 1.2533 * norm_rand(); tps[i].v[0] = out + n; //printf("~1 data %d: %f %f %f -> %f, inc noise %f\n", i, tps[i].p[0], tps[i].p[1], tps[i].p[2], out, tps[i].v[0]); tnoise += fabs(n); } tnoise /= (double) ntps; if (verb) printf("Measured noise average deviation = %f%%\n",tnoise * 100.0); /* Fit to scattered data */ if (verb) printf("Fitting the scattered data, smooth = %f, avgdev = %f\n",smooth,avgdev != NULL ? avgdev[0] : 0.0); avgdev[0] = 0.25 * noise; rss->fit_rspl(rss, flags, /* Non-mon and clip flags */ tps, /* Test points */ ntps, /* Number of test points */ low, high, gres, /* Low, high, resolution of grid */ low, high, /* Default data scale */ smooth, /* Smoothing to test */ avgdev, /* Average deviation */ NULL); /* iwidth */ /* Plot out function values */ if (plot) { int slice; printf("Black is target, Red is rspl\n"); for (slice = 0; slice < (di+1); slice++) { co tp; /* Test point */ double x[PLOTRES]; double ya[PLOTRES]; double yb[PLOTRES]; double yc[PLOTRES]; double pp[MXDI], p1[MXDI], p2[MXDI], ss[MXDI]; int n = PLOTRES; /* setup slices on each axis at 0.5 and diagonal */ if (slice < di) { for (j = 0; j < di; j++) p1[j] = p2[j] = 0.5; p1[slice] = 0.0; p2[slice] = 1.0; printf("Slice along axis %d\n",slice); } else { for (j = 0; j < di; j++) { p1[j] = 0.0; p2[j] = 1.0; } printf("Slice along diagonal\n"); } /* Start point and step increment */ for (j = 0; j < di; j++) { ss[j] = (p2[j] - p1[j])/n; pp[j] = p1[j]; } for (i = 0; i < n; i++) { double vv = i/(n-1.0); x[i] = vv; /* Reference */ ya[i] = lookup_func(&fp, pp); /* RSPL aproximation */ for (j = 0; j < di; j++) tp.p[j] = pp[j]; if (rss->interp(rss, &tp)) tp.v[0] = -0.1; yb[i] = tp.v[0]; /* Crude way of setting the scale: */ yc[i] = 0.0; if (i == (n-1)) yc[0] = 1.0; for (j = 0; j < di; j++) pp[j] += ss[j]; } /* Plot the result */ do_plot(x,ya,yb,yc,n); } } /* Compute statistics */ rmse = 0.0; avge = 0.0; maxe = 0.0; // so->reset(so); /* Fit to scattered data */ if (verb) printf("Fitting the scattered data\n"); for (i = 0; i <100000; i++) { co tp; /* Test point */ double aa, bb, err; so->next(so, tp.p); /* Reference */ aa = lookup_func(&fp, tp.p); /* RSPL aproximation */ rss->interp(rss, &tp); bb = tp.v[0]; err = fabs(aa - bb); avge += err; rmse += err * err; if (err > maxe) maxe = err; } avge /= (double)i; rmse /= (double)i; if (verb) printf("Dim %d, res %d, noise %f, points %d, maxerr %f%%, rmserr %f%%, avgerr %f%%\n", di, res, noise, ntps, maxe * 100.0, sqrt(rmse) * 100.0, avge * 100.0); *trmse += rmse; *tmaxe += maxe; *tavge += avge; rss->del(rss); free(tps); } so->del(so); *trmse = sqrt(*trmse/(double)its); *tmaxe /= (double)its; *tavge /= (double)its; }