#include "simfront.h" #include "timer.h" #define MAXREDUCS 20 int run_simulation(SimFront *sf) { MD_Sim *sim = sf->sim; double start, stop; /* start the clock */ start = time_of_day(); if (MD_init(sim) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_run(sim, sf->numsteps) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } /* stop the clock and find average time per step in seconds */ stop = time_of_day(); printf("# average time per step = %f\n", (stop - start) / sf->numsteps); #if 0 double reduc[MAXREDUCS]; MD_String reduclabel[MAXREDUCS]; MD_Int nreducs, idreduc, idreduclabel, idfirststep; MD_Int firststep, incrstep, laststep, step, k; if ((idreduc = MD_lookup(sim, "Reduction")) < 0) { ERRMSG(sf, "Reduction simulation parameter does not exist"); return -1; } else if (MD_DOUBLE != MD_getattr(sim, idreduc).typenum) { ERRMSG(sf, "unexpected type for Reduction simulation parameter"); return -1; } if ((idreduclabel = MD_lookup(sim, "ReductionLabel")) < 0) { ERRMSG(sf, "ReductionLabel simulation parameter does not exist"); return -1; } else if (MD_STRING != MD_getattr(sim, idreduclabel).typenum) { ERRMSG(sf, "unexpected type for ReductionLabel simulation parameter"); return -1; } if ((idfirststep = MD_lookup(sim, "FirstStepNum")) < 0) { firststep = 0; } else if (MD_INT != MD_getattr(sim, idfirststep).typenum) { ERRMSG(sf, "unexpected type for FirstStepNum simulation parameter"); return -1; } else if (MD_getdata(sim, idfirststep, &firststep, 1, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } nreducs = MD_getlen(sim, idreduc); if (nreducs > MAXREDUCS) nreducs = MAXREDUCS; if (nreducs > MD_getlen(sim, idreduclabel)) { nreducs = MD_getlen(sim, idreduclabel); } if (MD_getdata(sim, idreduclabel, reduclabel, nreducs, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } /* start the clock */ start = time_of_day(); /* initialize the simulation */ if (MD_init(sim) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_getdata(sim, idreduc, reduc, nreducs, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } printf("step %d:\n", firststep); for (k = 0; k < MD_getlen(sim, idreduc); k++) { printf(" %s = %g\n", reduclabel[k], reduc[k]); } /* run the simulation */ step = firststep; laststep = firststep + sf->numsteps; incrstep = sf->energyfreq; for ( ; step < laststep; step += incrstep) { if (MD_run(sim, incrstep) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } if (MD_getdata(sim, idreduc, reduc, nreducs, 0) || MD_wait(sim)) { ERRMSG(sf, MD_errmsg(sim)); return -1; } printf("step %d:\n", step + incrstep); for (k = 0; k < MD_getlen(sim, idreduc); k++) { printf(" %s = %g\n", reduclabel[k], reduc[k]); } } /* stop the clock and find average time per step in seconds */ stop = time_of_day(); printf("# average time per step = %f\n", (stop - start) / sf->numsteps); #endif return 0; }