void BcTest16(void) { enum { NUM_KEYS = ONE_MILLION }; static Key key[NUM_KEYS]; VAR_LUMP(v, MAX_DATA); Bc t; Key a; bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); BcInit(&t, KEY_LEN); for (i = 0; i < NUM_KEYS; i++) { a = RandKey(); key[i] = a; BcPut(&t, a.s, v); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { a = key[i]; BcGet(&t, a.s, &found); if (!found) fatal("didn't find %s", a.s); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); BcFree(&t); }
void BcTest7(void) { enum { NUM_RECS = 20 }; VAR_LUMP(v, MAX_DATA); Key key = {{0}}; Bc t; printf("%s\n", __FUNCTION__); init_twister(17); BcInit(&t, KEY_LEN); for (u64 i = 0; i < NUM_RECS; i++) { RandLump(v); BcPut(&t, RandKey().s, v); } BcDump(__FUNCTION__, &t); for (;;) { bool done; BcNext(&t, key.s, key.s, &done); if (done) { break; } BcDelete(&t, key.s); } BcDelete(&t, key.s); BcDump("Should be empty", &t); BcReport(__FUNCTION__, BcDoAudit(&t)); if (0) aver(t.root == NULL); BcFree(&t); }
void BcTest14(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; VAR_LUMP(v, MAX_DATA); Bc *t = emalloc(sizeof(*t) * NUM_ITER); u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); init_twister(17); RandLump(v); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BcInit(&t[j], KEY_LEN); for (i = 0; i < NUM_RECS; i++) { BcPut(&t[j], RandKey().s, v); } } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); BcReport(__FUNCTION__, BcDoAudit(&t[0])); for (j = 0; j < NUM_ITER; j++) { BcDoAudit(&t[j]); BcFree(&t[j]); } }
void TestPrTime(void) { init_twister(nsecs()); for (int i = 0; i < 50; i++) { u64 t = twister_urand(1ull<<i); printf("%3d. %16lld %s\n", i, t, TimeStringer(t).s); } }
void BcTest6(void) { enum { NUM_RECS = 2000, NUM_TRIALS = ONE_MILLION }; Bc t; VAR_LUMP(v, MAX_DATA); Key a[NUM_RECS]; u64 n = 0; u64 puts = 0; u64 deletes = 0; printf("%s\n", __FUNCTION__); init_twister(37); BcInit(&t, KEY_LEN); for (u64 j = 0; j < NUM_TRIALS; j++) { Key key; bool found; if (Prob(((NUM_RECS - n) * 100) / NUM_RECS)) { aver(n < NUM_RECS); key = IntKey(twister_urand(10000)); BcGet(&t, key.s, &found); if (!found) { a[n++] = key; RandLump(v); BcPut(&t, key.s, v); ++puts; } if (0 || Prob(2)) Audit("Put", &t, a, n, j); } else { aver(0 < n); u64 i = twister_urand(n); key = a[i]; BcGet(&t, key.s, &found); if (!found) { BcDump("not found", &t); fatal("didn't find %s %llu %llu", key.s, puts, deletes); } BcDelete(&t, key.s); BcGet(&t, key.s, &found); if (found) { BcDump("found", &t); fatal("found %llu", key); } a[i] = a[--n]; ++deletes; if (0 || Prob(2)) Audit("Delete", &t, a, n, j); } } BcDoAudit(&t); printf("\tputs=%llu deletes=%llu\n", puts, deletes); BcReport(__FUNCTION__, BcDoAudit(&t)); BcDump(__FUNCTION__, &t); BcFree(&t); }
void BbTest17(void) { enum { NUM_KEYS = ONE_MILLION }; static Key key[NUM_KEYS]; VAR_LUMP(v, MAX_DATA); Bb t; BB_ITER(iter, sizeof(Key)); bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); BbInit(&t, KEY_LEN); for (i = 0; i < NUM_KEYS; i++) { key[i] = RandKey(); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BbPut(&t, key[i].s, v); } dt = nsecs() - start; printf("BbPut: %llu nsecs %g nsecs/put op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BbGet(&t, key[i].s, &found); if (!found) fatal("didn't find %s", key[i].s); } dt = nsecs() - start; printf("BbGet: %llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); //BbIter *iter = BbIterNew(&t); BbIterInit(iter, &t); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { if (!BbIterNext(iter)) fatal("didn't find %s", iter->key); } dt = nsecs() - start; //BbIterFree(iter); printf("BbIter: %llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BbDelete(&t, key[i].s); } dt = nsecs() - start; printf("BbDelete: %llu nsecs %g nsecs/delete op\n", dt, (double)dt/(double)i); BbFree(&t); }
void BaTest6(void) { enum { NUM_RECS = 2000, NUM_TRIALS = ONE_MILLION }; Ba t; u64 a[NUM_RECS]; u64 n = 0; u64 puts = 0; u64 deletes = 0; printf("%s\n", __FUNCTION__); init_twister(17); BaInit(&t); for (u64 j = 0; j < NUM_TRIALS; j++) { u64 key; bool found; if (Prob(((NUM_RECS - n) * 100) / NUM_RECS)) { aver(n < NUM_RECS); key = twister_urand(10000); BaGet(&t, key, &found); if (!found) { a[n++] = key; BaPut(&t, key); ++puts; } if (0 || twister_urand(100) < 2) Audit("Put", &t, a, n, j); } else { aver(0 < n); u64 i = twister_urand(n); key = a[i]; BaGet(&t, key, &found); if (!found) { BaDump("not found", &t); fatal("didn't find %llu %llu %llu", key, puts, deletes); } BaDelete(&t, key); BaGet(&t, key, &found); if (found) { BaDump("found", &t); fatal("found %llu", key); } a[i] = a[--n]; ++deletes; if (0 || twister_urand(100) < 2) Audit("Delete", &t, a, n, j); } } BaDoAudit(&t); printf("\tputs=%llu deletes=%llu\n", puts, deletes); BaReportAudit(__FUNCTION__, BaDoAudit(&t)); BaDump(__FUNCTION__, &t); }
void BcTest18(void) { enum { NUM_KEYS = 1000 * ONE_THOUSAND }; static BigKey key[NUM_KEYS]; BigKey startKey = {{ 0 }}; VAR_LUMP(v, MAX_DATA); Bc t; BB_ITER(iter, sizeof(key[0])); bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); BcInit(&t, sizeof(key[0])); for (i = 0; i < NUM_KEYS; i++) { key[i] = RandBigKey(); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BcPut(&t, key[i].s, v); } dt = nsecs() - start; printf("BcPut: %llu nsecs %g nsecs/put op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BcGet(&t, key[i].s, &found); if (!found) fatal("didn't find %s", key[i].s); } dt = nsecs() - start; printf("BcGet: %llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); BcIterInit(iter, &t, startKey.s); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { if (!BcIterNext(iter)) fatal("didn't find %u. %s", i, iter->key); } dt = nsecs() - start; printf("BcIter: %llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BcDelete(&t, key[i].s); } dt = nsecs() - start; printf("BcDelete: %llu nsecs %g nsecs/delete op\n", dt, (double)dt/(double)i); BcFree(&t); }
void BaTest4(void) { enum { NUM_RECS = 20 }; Ba t; bool found; printf("%s\n", __FUNCTION__); init_twister(17); BaInit(&t); for (u64 i = 0; i < NUM_RECS; i++) { BaPut(&t, twister_random()); } init_twister(17); for (u64 i = 0; i < NUM_RECS; i++) { BaGet(&t, twister_random(), &found); if (!found) { fatal("didn't find %llu", i); } } BaDump(__FUNCTION__, &t); }
void BaTest2(void) { enum { NUM_RECS = 20 }; Ba t; printf("%s\n", __FUNCTION__); init_twister(17); BaInit(&t); for (u64 i = 0; i < NUM_RECS; i++) { BaPut(&t, twister_random()); } BaDump(__FUNCTION__, &t); }
void BcTest8(void) { /* * Extensive test of all functions. Want to cover most code paths. * 1. Dynamically adjust number of records by a factor of 100. * 2. Randomly pick operations. * 3. Test iteration intermixed with other operations. */ enum { MAX_RECS = 100 * ONE_THOUSAND }; Bc t; u64 key; u64 keys[MAX_RECS]; u64 numKeys = 0; u64 numPuts = 0; u64 numDeletes = 0; VAR_LUMP(v, MAX_DATA); init_twister(37); BcInit(&t, KEY_LEN); RandLump(v); for (u64 i = 0; i < 10; i++) { u64 maxKeys = twister_urand(MAX_RECS); PRu(maxKeys); while (numKeys != maxKeys) { aver(numKeys <= MAX_RECS); if (numKeys < maxKeys && Prob(75)) { key = twister_random(); keys[numKeys++] = key; BcPut(&t, IntKey(key).s, v); ++numPuts; } else { if (numKeys) { u64 j = twister_urand(numKeys); key = keys[j]; keys[j] = keys[--numKeys]; BcDelete(&t, IntKey(key).s); ++numDeletes; } } } } aver(numPuts - numDeletes == numKeys); PRu(numPuts); PRu(numDeletes); PRu(numKeys); BcReport(__FUNCTION__, BcDoAudit(&t)); }
void BzTest2(void) { enum { NUM_RECS = 100 }; VAR_LUMP(v, MAX_DATA); Bz t; printf("%s\n", __FUNCTION__); init_twister(17); BzInit(&t, KEY_LEN); for (u64 i = 0; i < NUM_RECS; i++) { if (1) IntLump(v, i); else IntLump(v, twister_urand(1000)); if (0) BzPut(&t, RandKey().s, v); else BzPut(&t, IntKey(twister_urand(1000)).s, v); } BzDump(__FUNCTION__, &t); }
void BaTest13(void) { enum { NUM_RECS = 10 * ONE_MILLION / 10 }; Ba t; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); init_twister(17); BaInit(&t); start = nsecs(); for (i = 0; i < NUM_RECS; i++) { BaPut(&t, twister_random()); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)i); BaReportAudit(__FUNCTION__, BaDoAudit(&t)); }
void BzTest17(void) { enum { NUM_KEYS = ONE_MILLION }; static Key key[NUM_KEYS]; VAR_LUMP(v, MAX_DATA); Bz t; bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); BzInit(&t, KEY_LEN); for (i = 0; i < NUM_KEYS; i++) { key[i] = RandKey(); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BzPut(&t, key[i].s, v); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/put op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BzGet(&t, key[i].s, &found); if (!found) fatal("didn't find %s", key[i].s); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BzDelete(&t, key[i].s); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/delete op\n", dt, (double)dt/(double)i); }
void BzTest13(void) { enum { NUM_RECS = 10 * ONE_MILLION / 10 }; VAR_LUMP(v, MAX_DATA); Bz t; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); init_twister(17); BzInit(&t, KEY_LEN); RandLump(v); start = nsecs(); for (i = 0; i < NUM_RECS; i++) { BzPut(&t, RandKey().s, v); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)i); BzReportAudit(__FUNCTION__, BzDoAudit(&t)); }
void BaTest14(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; Ba t; u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BaInit(&t); for (i = 0; i < NUM_RECS; i++) { BaPut(&t, twister_random()); } } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); BaReportAudit(__FUNCTION__, BaDoAudit(&t)); }
void BaTest17(void) { enum { NUM_KEYS = ONE_MILLION }; static u64 key[NUM_KEYS]; Ba t; bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); init_twister(17); BaInit(&t); for (i = 0; i < NUM_KEYS; i++) { key[i] = twister_random(); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BaPut(&t, key[i]); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/put op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BaGet(&t, key[i], &found); if (!found) fatal("didn't find %llu", key[i]); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BaDelete(&t, key[i]); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/delete op\n", dt, (double)dt/(double)i); }
void BzTest14(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; VAR_LUMP(v, MAX_DATA); Bz t; u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); init_twister(17); RandLump(v); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BzInit(&t, KEY_LEN); for (i = 0; i < NUM_RECS; i++) { BzPut(&t, RandKey().s, v); } } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); BzReportAudit(__FUNCTION__, BzDoAudit(&t)); }
void BcTest5(void) { enum { NUM_RECS = 20 }; VAR_LUMP(v, MAX_DATA); Key key = {{0}}; Lump a, b; Bc t; bool found; printf("%s\n", __FUNCTION__); init_twister(17); BcInit(&t, KEY_LEN); for (u64 i = 0; i < NUM_RECS; i++) { IntLump(v, i); BcPut(&t, RandKey().s, v); } BcDump(__FUNCTION__, &t); for (u64 i = 0;;i++) { bool done; a = BcNext(&t, key.s, key.s, &done); if (done) { if (i != NUM_RECS) fatal("Didn't find all the keys %llu %u", i, NUM_RECS); break; } b = BcGet(&t, key.s, &found); if (!found) { fatal("didn't find %llu", key); } aver(a.len == b.len); aver(strcmp(a.p, b.p) == 0); } BcDump(__FUNCTION__, &t); BcFree(&t); }
void BzTest15(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; VAR_LUMP(v, MAX_DATA); Bz t[NUM_ITER]; bool found; u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BzInit(&t[j], KEY_LEN); for (i = 0; i < NUM_RECS; i++) { BzPut(&t[j], RandKey().s, v); } } dt = nsecs() - start; printf("put %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { BzGet(&t[j], RandKey().s, &found); if (!found) { fatal("Didn't find key for iter %llu rec %llu", j, i); } } } dt = nsecs() - start; printf("get %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { Key key; bool isEof; BzNext(&t[j], RandKey().s, key.s, &isEof); if (!found) { fatal("Didn't find key for iter %llu rec %llu", j, i); } } } dt = nsecs() - start; printf("next %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { RandKey(); } } dt = nsecs() - start; printf("overhead %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); }
int main () /* Main function. */ { /* Open input and output files. */ infile = fopen ("jobshop.in", "r"); outfile = fopen ("jobshop.out", "w"); /* Read input parameters. */ fscanf (infile, "%d %d %lg %lg", &num_stations, &num_job_types, &mean_interarrival, &length_simulation); for (j = 1; j <= num_stations; ++j) fscanf (infile, "%d", &num_machines[j]); for (i = 1; i <= num_job_types; ++i) fscanf (infile, "%d", &num_tasks[i]); for (i = 1; i <= num_job_types; ++i) { for (j = 1; j <= num_tasks[i]; ++j) fscanf (infile, "%d", &route[i][j]); for (j = 1; j <= num_tasks[i]; ++j) fscanf (infile, "%lg", &mean_service[i][j]); } for (i = 1; i <= num_job_types; ++i) fscanf (infile, "%lg", &prob_distrib_job_type[i]); /* Write report heading and input parameters. */ fprintf (outfile, "Job-shop model\n\n"); fprintf (outfile, "Number of work stations%21d\n\n", num_stations); fprintf (outfile, "Number of machines in each station "); for (j = 1; j <= num_stations; ++j) fprintf (outfile, "%5d", num_machines[j]); fprintf (outfile, "\n\nNumber of job types%25d\n\n", num_job_types); fprintf (outfile, "Number of tasks for each job type "); for (i = 1; i <= num_job_types; ++i) fprintf (outfile, "%5d", num_tasks[i]); fprintf (outfile, "\n\nDistribution function of job types "); for (i = 1; i <= num_job_types; ++i) fprintf (outfile, "%8.3f", prob_distrib_job_type[i]); fprintf (outfile, "\n\nMean interarrival time of jobs%14.2f hours\n\n", mean_interarrival); fprintf (outfile, "Length of the simulation%20.1f eight-hour days\n\n\n", length_simulation); fprintf (outfile, "Job type Work stations on route"); for (i = 1; i <= num_job_types; ++i) { fprintf (outfile, "\n\n%4d ", i); for (j = 1; j <= num_tasks[i]; ++j) fprintf (outfile, "%5d", route[i][j]); } fprintf (outfile, "\n\n\nJob type "); fprintf (outfile, "Mean service time (in hours) for successive tasks"); for (i = 1; i <= num_job_types; ++i) { fprintf (outfile, "\n\n%4d ", i); for (j = 1; j <= num_tasks[i]; ++j) fprintf (outfile, "%9.2f", mean_service[i][j]); } /* Initialize rndlib */ init_twister(); /* Initialize all machines in all stations to the idle state. */ for (j = 1; j <= num_stations; ++j) num_machines_busy[j] = 0; /* Initialize simlib */ init_simlib (); /* Set maxatr = max(maximum number of attributes per record, 4) */ maxatr = 4; /* NEVER SET maxatr TO BE SMALLER THAN 4. */ /* Schedule the arrival of the first job. */ event_schedule (expon (mean_interarrival, STREAM_INTERARRIVAL), EVENT_ARRIVAL); /* Schedule the end of the simulation. (This is needed for consistency of units.) */ event_schedule (8 * length_simulation, EVENT_END_SIMULATION); /* Run the simulation until it terminates after an end-simulation event (type EVENT_END_SIMULATION) occurs. */ do { /* Determine the next event. */ timing (); /* Invoke the appropriate event function. */ switch (next_event_type) { case EVENT_ARRIVAL: arrive (1); break; case EVENT_DEPARTURE: depart (); break; case EVENT_END_SIMULATION: report (); break; } /* If the event just executed was not the end-simulation event (type EVENT_END_SIMULATION), continue simulating. Otherwise, end the simulation. */ } while (next_event_type != EVENT_END_SIMULATION); fclose (infile); fclose (outfile); return 0; }
int main() { // load datafiles parse_input("adal_inntak.in","velar_og_bidradir.in"); // initialize arrays and variables if((fail_list = malloc(sizeof(breakdown)*NUM_MACHINES+1))==NULL) { printf("Allocation Error\n"); exit(1); } for (failure_nr = min_no_failures; failure_nr<= max_no_failures; failure_nr++) { stream = (unsigned int)time(NULL) % 100; memset( is_machine_busy,0, NUM_MACHINES +1 ); memset( machine_broken,0, NUM_MACHINES +1); memset( queue_max_lengths,0, NUM_MACHINES +1); memset( fail_list,0, sizeof(breakdown)*(NUM_MACHINES+1)); fail_index = 0; skaut_throughput = 0; sampst_delays = number_of_machines +1; throughput_time = number_of_machines +2; skaut_id = 1; skaut_throughput = 0; // Initialize rndlib init_twister(); // Initialize simlib init_simlib(); maxatr = 6; // how many attributes do we need? /* Schedule first wagen arrival */ event_schedule( 10.0, EVENT_WAGEN_UNLOAD_ARRIVAL ); /* Schedule end of warmup time */ event_schedule( end_warmup_time, EVENT_END_WARMUP ); event_schedule(end_warmup_time, EVENT_GENERATE_FAILURES ); /* Schedule simulation termination */ event_schedule(end_simulation_time , EVENT_END_SIMULATION ); next_event_type = 0; while (next_event_type != EVENT_END_SIMULATION) { timing(); switch (next_event_type) { case EVENT_WAGEN_UNLOAD_ARRIVAL: wagen_unload_arrival(); break; case EVENT_SKAUT_ARRIVAL: skaut_arrival(); break; case EVENT_SKAUT_DEPARTURE: skaut_departure(); break; case EVENT_MACHINE_FAILURE: machine_failure(); break; case EVENT_MACHINE_FIXED: machine_fixed(); break; case EVENT_END_WARMUP: end_warmup(); break; case EVENT_END_SIMULATION: report(); break; case EVENT_GENERATE_FAILURES: create_machine_fail_events(); break; } } } }