void clock_toggle() { if(timer_counting) clock_stop(); else clock_start(); }
/* * Configure PORT_1A as data with PORT_1B as the valid signal. Ensure that the * receiver is ready using a channel end. Send a word of data, delay for a while * and send another word to ensure the valid signals are functioning. */ void port_test_output(chanend c) { port p = port_enable(XS1_PORT_1A); port_set_buffered(p); port_set_transfer_width(p, 32); port p_ready = port_enable(XS1_PORT_1B); clock clk = clock_enable(XS1_CLKBLK_1); clock_start(clk); port_configure_out_strobed_master(p, p_ready, clk, 0); chan_input_word(c); // Wait for ack port_output(p, 0xfeedbeef); timer tmr = timer_alloc(); timer_delay(tmr, 1000); timer_free(tmr); port_output(p, 0x12345678); chan_input_word(c); // Wait for ack port_disable(p); port_disable(p_ready); clock_disable(clk); // Get information about the tile/core running the server for debug messages unsigned tile_id = get_local_tile_id(); unsigned core_id = get_logical_core_id(); debug_printf("%x:%d: output done\n", tile_id, core_id); }
/* * Configure PORT_1C as data with PORT_1D as the valid signal. Test receiving * two different words of data and check they are the correct values. */ void port_test_input(chanend c) { port p = port_enable(XS1_PORT_1C); port_set_buffered(p); port_set_transfer_width(p, 32); port p_ready = port_enable(XS1_PORT_1D); clock clk = clock_enable(XS1_CLKBLK_2); clock_start(clk); port_configure_in_strobed_slave(p, p_ready, clk); chan_output_word(c, 0); // Send ack unsigned int x = port_input(p); if (x != 0xfeedbeef) { debug_printf("Error %x received instead of 0xfeedbeef\n", x); } x = port_input(p); if (x != 0x12345678) { debug_printf("Error %x received instead of 0x12345678\n", x); } chan_output_word(c, 0); // Send ack port_disable(p); port_disable(p_ready); clock_disable(clk); // Get information about the tile/core running the server for debug messages unsigned tile_id = get_local_tile_id(); unsigned core_id = get_logical_core_id(); debug_printf("%x:%d: input done\n", tile_id, core_id); }
/* PUBLIC */ void index_denial(Topform c, Indexop op, Clock clock) { BOOL unit = (number_of_literals(c->literals) == 1); clock_start(clock); lindex_update(unit ? Unit_fpa_idx : Nonunit_fpa_idx, c, op); clock_stop(clock); } /* index_denial */
/* PUBLIC */ void set_semantics(Topform c) { if (c->semantics == SEMANTICS_NOT_EVALUATED) { clock_start(Eval_clock); eval_in_interps(c); clock_stop(Eval_clock); } } /* set_semantics */
void h8_sci_device::rx_start() { ssr |= SSR_TDRE; rx_parity = smr & SMR_OE ? 0 : 1; rsr = 0x00; logerror("%s: start recieve\n", tag()); if(smr & SMR_CA) { rx_state = ST_BIT; rx_bit = 8; clock_start(CLK_RX); } else { rx_state = ST_START; rx_bit = 1; if(!rx_value) clock_start(CLK_RX); } }
int main(int argc, char *argv[]){ unsigned int i; int sym; SSS_Matrix m; Clock clock; char* filename; double *x; double *y; parse_args(argc, argv); filename = argv[1]; // Initialize matrices. sss_init_matrix(&m); // Load matrix from file //printf("Loading matrix \"%s\"\n", filename); sym = sss_load_matrix(filename, &m); // If matrix is non-symmetric, this call fails. //printf("Matrix is symmetric\n"); // Print Matrix data //printf("SSS matrix data:\n"); //sss_print_matrix(&m); // Initialize vectors for multiplication x = (double *)malloc(m.cols * sizeof(double)); y = (double *)malloc(m.rows * sizeof(double)); for(i = 0; i < m.cols; i++){ x[i] = i+1; } //print_vector("\nx= ", x, m.cols); // Time matrix-vector product //printf("Calculating matrix-vector product for %u iterations...\n", iterations); clock_start(&clock); for(i=0; i < iterations; i++){ sss_mvp2_sym(&m,x,y); } clock_stop(&clock); //printf("SSS mvp time: %.2fus \n\n", clock.sec); //print_vector("y= \n", y, m.rows); // Print minimal info for testing purposes printf("%s\t%.2f\n", filename, clock.sec); // Free resources free(x); free(y); sss_free_matrix(&m); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { size = 10; rank = 0; MPI_Init(&argc,&argv); clOptions options; if(getCla(argc, argv, &options)) { //NOTHING TO WORRY ABOUT } else { printf("command line options failure\n"); return 1; } clock_start(); takeTime(10); clock_stop(argv[0], options, "words"); clock_start(); takeTime(100); clock_stop(argv[0], options, "x1000"); clock_start(); takeTime(1000); clock_stop(argv[0], options, "E6"); char * newtag; newtag = "hardcoded_string"; clock_start(); takeTime(100); clock_stop(argv[0], options, newtag); MPI_Finalize(); }
void h8_sci_device::tx_start() { ssr |= SSR_TDRE; tsr = tdr; tx_parity = smr & SMR_OE ? 0 : 1; logerror("%s: start transmit %02x\n", tag(), tsr); if(scr & SCR_TIE) intc->internal_interrupt(txi_int); if(smr & SMR_CA) { tx_state = ST_BIT; tx_bit = 8; } else { tx_state = ST_START; tx_bit = 1; } clock_start(CLK_TX); }
int main(void) { const long iterations = 1000000000; struct timespec ts; uint64_t tsc; clock_start (&ts); tsc_start(&tsc); volatile int asignto = 0; for (long i = 0; i < iterations; i++) { asignto = function_call(i); } const long long unsigned delta = clock_end(&ts); const long long unsigned delta_tsc = tsc_end(&tsc); (void) asignto; printf("%ld spins in %lluns (%.1fns/spin, %.1f clocks/spin)\n", iterations, delta, (delta / (double) iterations),delta_tsc / (double)iterations); return 0; }
void h8_sci_device::tx_start() { ssr |= SSR_TDRE; tsr = tdr; tx_parity = smr & SMR_OE ? 0 : 1; if(V>=1) logerror("start transmit %02x '%c'\n", tsr, tsr >= 32 && tsr < 127 ? tsr : '.'); if(scr & SCR_TIE) intc->internal_interrupt(txi_int); if(smr & SMR_CA) { tx_state = ST_BIT; tx_bit = 8; } else { tx_state = ST_START; tx_bit = 1; } clock_start(CLK_TX); if(rx_state == ST_IDLE && !has_recv_error() && is_sync_start()) rx_start(); }
/* PUBLIC */ void index_literals(Topform c, Indexop op, Clock clock, BOOL no_fapl) { BOOL unit = (number_of_literals(c->literals) == 1); clock_start(clock); if (!no_fapl || !positive_clause(c->literals)) lindex_update(unit ? Unit_fpa_idx : Nonunit_fpa_idx, c, op); if (unit) lindex_update(Unit_discrim_idx, c, op); else { Ilist f = features(c->literals); if (op == INSERT) di_tree_insert(f, Nonunit_features_idx, c); else di_tree_delete(f, Nonunit_features_idx, c); zap_ilist(f); } clock_stop(clock); } /* index_literals */
// For PB1 void GPIO_EVEN_IRQHandler() { switch (state) { case STATE_SET_SEC: { state = STATE_SET_MIN; } break; case STATE_SET_MIN: { state = STATE_SET_HOUR; } break; case STATE_SET_HOUR: { state = STATE_COUNT_DOWN; clock_start(); } break; case STATE_COUNT_DOWN: break; case STATE_ALARM: { state = STATE_SET_SEC; GPIO->ports[LED_PORT].DOUTCLR = 1 << LED_PIN; } break; } GPIO->IFC = 1 << PB1_PIN; }
void InitRun(enum State *state) { gMin = stime[0]; gSec = stime[1]; if (gMin > 0 || gSec > 0) { // count down gDirection = -1; *state = ST_RUN_AUTO; } else { // count up gDirection = 1; *state = ST_RUN_MANUAL; } // open the shutter and start the clock SHUTTER_ON(); clock_start(); }
void profit_solve(graph g, vector<int>& allocation, vector<double>& pricing, bool integer) { int **columns = (int **)malloc(g->bidders * sizeof(int *)); for(int i = 0; i < g->bidders; i++) columns[i] = (int *)calloc(g->items, sizeof(int)); IloEnv env; try { if(getVerbosity() != CplexOutput) env.setOut(env.getNullStream()); IloModel model(env); IloNumVarArray x(env); IloNumVarArray p(env); IloNumVarArray z(env); IloCplex cplex(model); profit_create_vars(g, model, x, p, z, columns); profit_create_objective(g, model, x, z, columns); model.add(profit_constraints(g, model, x, p, z, columns)); config_cplex(cplex); if(!integer) { model.add(IloConversion(env, x, ILOFLOAT)); } else { profit_load(g, cplex, model, x, p, z, columns, allocation, pricing); } clock_start(); if (!cplex.solve()) { failed_print(g); } else { if(integer) solution_print(cplex, env, g); else relax_print(cplex, env); } } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } }
int main(void) { struct sched_param param; param.sched_priority = 1; if (sched_setscheduler(getpid(), SCHED_RR, ¶m)) fprintf(stderr, "sched_setscheduler(): %s\n", strerror(errno)); struct timespec ts; pthread_t thd; clock_start(&ts); if (pthread_create(&thd, NULL, thread, NULL)) { return 1; } for (int i = 0; i < iterations; i++) sched_yield(); void *retval = NULL; unsigned long long delta = clock_end(&ts); pthread_join(thd, &retval); const int nswitches = iterations << 1; printf("%i sched_yield()'s in %lluns (%.1fns/ctxsw)\n", nswitches, delta, (delta / (float) nswitches)); return 0; }
int main(int argc, char ** argv){ //MPI Initialization MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); clOptions options; if(getCla(argc, argv, &options)){ //NOTHING TO WORRY ABOUT }else{ printf("command line options failure\n"); return 1; } MPI_Status status_ignore; //MPI Particle Initialization //MPI_Datatype MPI_particle; create_MPI_struct(&MPI_particle); MPI_Type_commit(&MPI_particle); //Deprecated and dangerous as superseded by options structure //char * readFName =NULL; //char * writeFName = NULL; //char * defaultFName = "default.dat"; //int writeData = 0; //int compareData = 0; //change to allow command line arguments //Setup if(options.timing >=1){ clock_start(); } char * initTypeTimingTag = "undefined_tag"; int nParticles = options.nParticles; int nEachMax = pieceSize(nParticles, size, 0); double diff; particle * buffers[4]; particle * spare_particle_pointer; buffers[0] = calloc(sizeof(particle), nEachMax); buffers[1] = calloc(sizeof(particle), nEachMax); buffers[2] = calloc(sizeof(particle), nEachMax); buffers[3] = calloc(sizeof(particle), nEachMax); int buf_index[3] = {rank, rank, rank}; int nEach[3]; nEach[0] = pieceSize(nParticles, size, rank); nEach[1] = pieceSize(nParticles, size, rank); nEach[2] = pieceSize(nParticles, size, rank); //diff =compareMultipleParticles(buffers[0], buffers[1], nEachMax); //Read or Randomize and print if(options.readInput == 1){ if(options.verbosity>=2){ printf("reading particles\n"); } initTypeTimingTag = "init_read"; readParticles(options.readFName, buffers[3], nParticles, size, rank); }else if(options.genFunction == 2){ if(options.verbosity>=2){ printf("generating particles\n"); } initTypeTimingTag = "init_gen2"; initialize_2(buffers[3], nEachMax); //fprintParticles(stdout, buffers[3], nEachMax); }else{ //no input printf("error: no initial data specified\n"); MPI_Finalize(); } if(options.verbosity>=2){ printf("should have particles now\n"); } int i; for(i=0;i<nEachMax;i++){ buffers[0][i] = buffers[3][i]; buffers[0][i].dvx = 0; buffers[0][i].dvy = 0; buffers[0][i].dvz = 0; buffers[1][i] = buffers[0][i]; buffers[2][i] = buffers[0][i]; } if(options.verbosity>=3){ printf("rank %d printing particles set 0 \n", rank); fprintParticles(stdout, buffers[0], nEachMax); printf("rank %d printing particles set 1 \n", rank); fprintParticles(stdout, buffers[1], nEachMax); printf("rank %d printing particles set 2 \n", rank); fprintParticles(stdout, buffers[2], nEachMax); printf("rank %d printing particles set 3 \n", rank); fprintParticles(stdout, buffers[3], nEachMax); } //diff =compareMultipleParticles(buffers[0], buffers[3], nEachMax); //printf("rank %d diff = %g \t\t expected different \n", rank, diff); //Loop //Pass //Calculate //Collect if(options.timing == 2){ clock_stop(argv[0], options, initTypeTimingTag); } if(options.timing >=1){ clock_start(); } int j; int passTimes; int passingBuffer = 0; for(passTimes = size; passTimes >0;passTimes -=3){ for(i=0;i<passTimes;i++){ MPI_pass(buffers, passingBuffer, nEachMax, 1, buf_index); nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]); printf("pass:%d:\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]); func(buffers, nEach, buf_index); } if(passTimes ==3){passTimes+=1;} passingBuffer == (passingBuffer+1)%3; } //Passing to rank that should have particle buffer if(options.verbosity>=0){ printf("old:%d\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]); } int dist; passingBuffer =0; dist = (rank *2 - buf_index[passingBuffer])%size; MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index); nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]); passingBuffer =1; dist = (rank *2 - buf_index[passingBuffer])%size; MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index); nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]); passingBuffer =2; dist = (rank *2 - buf_index[passingBuffer])%size; MPI_pass(buffers, passingBuffer, nEachMax, dist, buf_index); nEach[passingBuffer] = pieceSize(nParticles, size, buf_index[passingBuffer]); if(options.verbosity>=0){ printf("new:%d\t%d\t%d\t%d\n", rank, buf_index[0], buf_index[1], buf_index[2]); } if(options.verbosity>=3){ printf("combining results\n"); } if(options.verbosity>=3){ printf("rank %d printing particles set 0 \n", rank); fprintParticles(stdout, buffers[0], nEachMax); printf("rank %d printing particles set 1 \n", rank); fprintParticles(stdout, buffers[1], nEachMax); printf("rank %d printing particles set 2 \n", rank); fprintParticles(stdout, buffers[2], nEachMax); printf("rank %d printing particles set 3 \n", rank); fprintParticles(stdout, buffers[3], nEachMax); } //Combine results for(i=0;i<nEach[0];i++){ buffers[0][i].dvx += buffers[1][i].dvx+buffers[2][i].dvx; //buffers[0][i].dvx /= 6; buffers[1][i].dvx = buffers[0][i].dvx; buffers[2][i].dvx = buffers[0][i].dvx; buffers[0][i].dvy += buffers[1][i].dvy+buffers[2][i].dvy; //buffers[0][i].dvy /= 6; buffers[1][i].dvy = buffers[0][i].dvy; buffers[2][i].dvy = buffers[0][i].dvy; buffers[0][i].dvz += buffers[1][i].dvz+buffers[2][i].dvz; //buffers[0][i].dvz /= 6; buffers[1][i].dvz = buffers[0][i].dvz; buffers[2][i].dvz = buffers[0][i].dvz; } if(options.timing >= 1){ clock_stop(argv[0], options, "no_duplicates"); } if(rank == 0){ //fprintParticles(stdout, buffers[3], nEachMax); //fprintParticles(stdout, buffers[0], nEachMax); } //Check results //use buffers[3] if(options.compareResults == 1){ if(options.verbosity>=2){ printf("comparing results"); } if(options.timing == 2){ clock_start(); } diff =compareMultipleParticles(buffers[0], buffers[3], nEach[0]); if(options.timing == 2){ clock_stop(argv[0], options, "comparison"); } printf("rank %d diff = %g\n", rank, diff); } if(options.writeOutput == 1){ if(options.timing == 2){ clock_start(); } writeParticles(options.writeFName, buffers[0], nParticles, size, rank); if(options.timing == 2){ clock_stop(argv[0], options, "writing"); } } //freeing and finalization free(buffers[0]); free(buffers[1]); free(buffers[2]); free(buffers[3]); //MPI Finalization MPI_Type_free(&MPI_particle); MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); }
int main(void) { // Initialize I/O DDRB = 0x3e; // 00111110 PORTB = 0x01; // 00000001 DDRC = 0x20; // 00100000 PORTC = 0x03; // 00000011 DDRD = 0xff; // 11111111 PORTD = 0xff; // 11111111 // Load saved state, if any Load(); // Setup the display timer... // prescaler 1/8; at 1MHz system clock, this gives us an overflow // at 488 Hz, providing a per-digit refresh rate of 97.6 Hz. TCCR0A = 0; TCCR0B = (1<<CS01); // Output compare value B - controls blanking. // In full brightness mode, we'll make this happen immediately before the refresh, // In lower brightness modes, we'll make it happen sooner. OCR0A = pgm_read_byte(&brighttable[bright]); // Enable overflow and compare match interrupts TIMSK0 = (1<<TOIE0) | (1<<OCIE0A); // Setup the RTC... gMin = 0; gSec = 0; // select asynchronous operation of Timer2 ASSR = (1<<AS2); // select prescaler: 32.768 kHz / 128 = 1 sec between each overflow TCCR2A = 0; TCCR2B = (1<<CS22) | (1<<CS20); // wait for TCN2UB and TCR2UB to be cleared while((ASSR & 0x01) | (ASSR & 0x04)); // clear interrupt-flags TIFR2 = 0xFF; // init the state machine enum State state = ST_TIME; enum State prevstate = ST_TIME; uint8_t remaining = 0; uint8_t cmode = 0; // Enable interrupts sei(); // Do some stuff for(;;) { uint8_t buttons = GetButtons(); if ((buttons & BUTTON_RIGHT) && (state < ST_BRIGHT)) { prevstate = state; remaining = count; cmode = 0; buttons = 0; state = ST_RUN_PRIME; } newstate: switch(state) { case ST_TIME: DisplayNum(stime[0], HIGH_POS, 0, 3); display[COLON_POS] = COLON; DisplayNum(stime[1], LOW_POS, 0, 0); if (buttons & BUTTON_LEFT) { state = ST_DELAY; } else if (buttons & BUTTON_UP) { state = ST_TIME_SET_MINS; } break; case ST_DELAY: DisplayNum(delay[0], HIGH_POS, 0, 3); display[COLON_POS] = LOWDOT; DisplayNum(delay[1], LOW_POS, 0, 0); if (buttons & BUTTON_LEFT) { state = ST_COUNT; } else if (buttons & BUTTON_UP) { state = ST_DELAY_SET_MINS; } break; case ST_COUNT: DisplayAlnum('\xC6', count, 0); if (buttons & BUTTON_LEFT) { state = ST_MLU; } else if (buttons & BUTTON_UP) { state = ST_COUNT_SET; } break; case ST_MLU: DisplayAlnum('\xC7', mlu, 0); if (buttons & BUTTON_LEFT) { state = ST_BRIGHT; } else if (buttons & BUTTON_UP) { state = ST_MLU_SET; } break; /* I'll put this in once there's more than one option ;) case ST_OPTIONS: display[0] = '\xC0'; // 00111111 = 'O' display[1] = '\x8C'; // 01110011 = 'P' display[2] = EMPTY; display[3] = '0x87'; // 01111000 = 't' display[4] = '0x92'; // 01101101 = 'S' if (buttons & BUTTON_LEFT) { state = ST_TIME; } else if (buttons & BUTTON_UP) { state = ST_BRIGHT; } break; */ case ST_BRIGHT: DisplayAlnum('\x83', 4 - bright, 0); // 10000011 = 'b' if (buttons & BUTTON_LEFT) { state = ST_TIME; } else if (buttons & BUTTON_UP) { bright = (bright - 1) & 3; OCR0A = pgm_read_byte(&brighttable[bright]); } else if (buttons & BUTTON_RIGHT) { Save(); state = ST_SAVED; remaining = 15; } break; case ST_SAVED: display[0] = '\x92'; // 01101101 = 'S' display[1] = '\x88'; // 01110111 = 'A' display[2] = EMPTY; display[3] = '\xc1'; // 00111110 = 'V' display[4] = '\x86'; // 01111001 = 'E' if (--remaining == 0) state = ST_BRIGHT; break; case ST_TIME_SET_MINS: DisplayNum(stime[0], HIGH_POS, 0x40, 0); display[COLON_POS] = COLON; DisplayNum(stime[1], LOW_POS, 0, 0); if (EditNum(&stime[0], buttons, 100)) { state = ST_TIME_SET_SECS; } break; case ST_TIME_SET_SECS: DisplayNum(stime[0], HIGH_POS, 0, 0); display[COLON_POS] = COLON; DisplayNum(stime[1], LOW_POS, 0x40, 0); if (EditNum(&stime[1], buttons, 60)) { state = ST_TIME; } break; case ST_DELAY_SET_MINS: DisplayNum(delay[0], HIGH_POS, 0x40, 0); display[COLON_POS] = LOWDOT; DisplayNum(delay[1], LOW_POS, 0, 0); if (EditNum(&delay[0], buttons, 100)) { state = ST_DELAY_SET_SECS; } break; case ST_DELAY_SET_SECS: DisplayNum(delay[0], HIGH_POS, 0, 0); display[COLON_POS] = LOWDOT; DisplayNum(delay[1], LOW_POS, 0x40, 0); if (EditNum(&delay[1], buttons, 60)) { state = ST_DELAY; } break; case ST_COUNT_SET: DisplayAlnum('\xC6', count, 0x40); if (EditNum(&count, buttons, 100)) { state = ST_COUNT; } break; case ST_MLU_SET: DisplayAlnum('\xC7', mlu, 0x40); if (EditNum(&mlu, buttons, 60)) { state = ST_MLU; } break; case ST_RUN_PRIME: if (mlu > 0) { state = ST_MLU_PRIME; SHUTTER_ON(); DisplayAlnum('\xC7', mlu, 0); } else { InitRun(&state); goto newstate; } break; case ST_RUN_AUTO: if (gDirection == 0) { // time has elapsed. close the shutter and stop the timer. SHUTTER_OFF(); clock_stop(); if (remaining > 0) { if (--remaining == 0) { // we're done. state = prevstate; break; } } gMin = delay[0]; gSec = delay[1]; gDirection = -1; state = ST_WAIT; clock_start(); goto newstate; } // fall through case ST_RUN_MANUAL: if (cmode == 0) { // time left in this exposure DisplayNum(gMin, HIGH_POS, 0, 3); DisplayNum(gSec, LOW_POS, 0, 0); } else { // remaining exposures DisplayAlnum('\xC6', remaining, 0); } display[COLON_POS] = (TCNT2 & 0x80) ? EMPTY : COLON; break; case ST_MLU_PRIME: SHUTTER_OFF(); gMin = 0; gSec = mlu; gDirection = -1; state = ST_MLU_WAIT; clock_start(); // fall-through case ST_MLU_WAIT: DisplayAlnum('\xC7', gSec, 0); if (gDirection == 0) { // MLU wait period has elapsed clock_stop(); InitRun(&state); goto newstate; } break; case ST_WAIT: if (cmode == 0) { // wait time DisplayNum(gMin, HIGH_POS, 0, 3); DisplayNum(gSec, LOW_POS, 0, 0); } else { // remaining exposures DisplayAlnum('\xC6', remaining, 0); } display[COLON_POS] = (TCNT2 & 0x80) ? EMPTY : LOWDOT; if (gDirection == 0) { // wait period has timed out; // stop the timer and start a new cycle clock_stop(); state = ST_RUN_PRIME; goto newstate; } break; } if (state >= ST_RUN_PRIME) { // check keys if (buttons & BUTTON_RIGHT) { // canceled. clock_stop(); SHUTTER_OFF(); // if counting up, freeze the count here if (state == ST_RUN_MANUAL) { stime[0] = gMin; stime[1] = gSec; } state = prevstate; } else if ((buttons & BUTTON_LEFT) && (count > 1)) { // toggle display, time left vs. count left cmode = (cmode + 1) & 1; } else if (buttons & BUTTON_UP) { // adjust brightness bright = (bright - 1) & 3; OCR0A = pgm_read_byte(&brighttable[bright]); } } Sleep(48); // approx 50ms at 1MHz } }
int main(int argc, char *argv[]) { int ret = 0; if (argc < 2) { fprintf(stderr, "Usage: transalign_killer [--cldev=x.y] <input file>\n"); fprintf(stderr, " --cldev=x.y: x specifies the platform index, y the device index.\n"); return 1; } long seq_length; char *sequence = load_text(argv[argc - 1], &seq_length); if (!sequence) return 1; seq_length--; // Cut final 0 byte // FIXME: All the following code relies on seq_length being a multiple of BASE. long round_seq_length = round_up_to_power_of_two(seq_length, BASE_EXP); long res_length = 0; for (long len = round_seq_length / BASE; len; len /= BASE) res_length += len; // Use some random index to be searched for here unsigned letter_index = seq_length / 2; // Select an OpenCL device cl_device_id dev = select_device(argc - 1, argv); if (!dev) return 1; // Initialize the OpenCL st...ack cl_context ctx = clCreateContext(NULL, 1, &dev, NULL, NULL, NULL); cl_command_queue queue = clCreateCommandQueue(ctx, dev, 0, NULL); // Load the OpenCL kernesl char *prog_src = load_text("trans.cl", NULL); if (!prog_src) return 1; cl_program prog = clCreateProgramWithSource(ctx, 1, (const char **)&prog_src, NULL, NULL); free(prog_src); // Build them clBuildProgram(prog, 0, NULL, NULL, NULL, NULL); cl_kernel k_iadd = clCreateKernel(prog, "k_iadd", NULL); // initial addition cl_kernel k_cadd = clCreateKernel(prog, "k_cadd", NULL); // consecutive addition assert(k_iadd); assert(k_cadd); // Create the result buffer unsigned *result = malloc(res_length * sizeof(unsigned)); cl_mem result_gpu = clCreateBuffer(ctx, CL_MEM_READ_WRITE | HOST_PTR_POLICY, res_length * sizeof(unsigned), result, NULL); clock_start(); /*** START OF ROCKET SCIENCE LEVEL RUNTIME-TIME INTENSIVE STUFF ***/ // Bandwidth intensive stuff goes here // Copy the sequence to the video memory (or, generally speaking, the OpenCL device) cl_mem seq_gpu = clCreateBuffer(ctx, CL_MEM_READ_WRITE | HOST_PTR_POLICY, seq_length * sizeof(char), sequence, NULL); long bw1_time = clock_delta(); // GPU intensive stuff goes here /** * First, transform every - and \0 into a 0 and every other character into a * 1. Then, add consecutive fields (BASE fields) together and store them at * the beginning of the result buffer. */ clSetKernelArg(k_iadd, 0, sizeof(result_gpu), &result_gpu); clSetKernelArg(k_iadd, 1, sizeof(seq_gpu), &seq_gpu); clSetKernelArg(k_iadd, 2, sizeof(unsigned), &(unsigned){seq_length});
int main(int argc, char *argv[]){ unsigned int i; int sym; CSR_Matrix csr; Clock clock; char* filename; double *x; double *y; parse_args(argc, argv); filename = argv[1]; // Initialize matrices. csr_init_matrix(&csr); // Load matrix from file into COO. printf("Loading matrix \"%s\"\n", filename); sym = csr_load_matrix(filename, &csr); if(sym) printf("Matrix is symmetric\n"); else printf("Matrix is general (non-symmetric)\n"); // Print Matrix data //printf("CSR matrix data:\n"); //csr_print_matrix(&csr); // Initialize vectors for multiplication x = (double *)malloc(csr.cols * sizeof(double)); y = (double *)malloc(csr.rows * sizeof(double)); for(i = 0; i < csr.cols; i++){ x[i] = i+1; } //print_vector("\nx= ", x, coo.cols); printf("Calculating matrix-vector product for %u iterations...\n", iterations); if(sym){ // Time CSR matrix-vector product // clock_start(&clock); // for(i=0; i < iterations; i++){ // csr_mvp_sym(&csr,x,y); // } // clock_stop(&clock); // printf("CSR mvp time: %.2fus \n", clock.sec); // Time CSR matrix-vector product clock_start(&clock); for(i=0; i < iterations; i++){ csr_mvp_sym2(&csr,x,y); } clock_stop(&clock); printf("CSR mvp2 time: %.2fus \n\n", clock.sec); // Time CSR matrix-vector product // clock_start(&clock); // for(i=0; i < iterations; i++){ // csr_mvp_sym_oski_lo(&csr,x,y); // } // clock_stop(&clock); // printf("CSR mvp oski time: %.2fus \n\n", clock.sec); // Time CSR matrix-vector product // clock_start(&clock); // for(i=0; i < iterations; i++){ // csr_mvp_sym_oski2(&csr,x,y); // } // clock_stop(&clock); // printf("CSR mvp oski2 time: %.2gs \n", clock.sec); //print_vector("y= ", y, csr.rows); }else{ // Time CSR matrix-vector product // clock_start(&clock); // for(i=0; i < iterations; i++){ // csr_mvp(&csr,x,y); // } // clock_stop(&clock); // printf("CSR mvp time: %.2gs \n", clock.sec); //print_vector("y= ", y, csr.cols); // Time CSR matrix-vector product // clock_start(&clock); // for(i=0; i < iterations; i++){ // csr_mvp2(&csr,x,y); // } // clock_stop(&clock); // printf("CSR mvp2 time: %.2gs \n", clock.sec); //print_vector("y= ", y, csr.cols); // Time CSR matrix-vector product // clock_start(&clock); // for(i=0; i < iterations; i++){ // csr_mvp_oski(&csr,x,y); // } // clock_stop(&clock); // printf("CSR mvp oski time: %.2gs \n", clock.sec); //print_vector("y= ", y, csr.cols); // Time CSR matrix-vector product clock_start(&clock); for(i=0; i < iterations; i++){ csr_mvp_oski2(&csr,x,y); } clock_stop(&clock); printf("CSR mvp oski2 time: %.2gs \n\n", clock.sec); //print_vector("y= ", y, csr.cols); } // Free resources free(x); free(y); csr_free_matrix(&csr); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { ecdsa_t *key1, *key2; ecdh_t *ecdh1, *ecdh2; sptps_t sptps1, sptps2; char buf1[4096], buf2[4096], buf3[4096]; double duration = argc > 1 ? atof(argv[1]) : 10; crypto_init(); randomize(buf1, sizeof buf1); randomize(buf2, sizeof buf2); randomize(buf3, sizeof buf3); // Key generation fprintf(stderr, "Generating keys for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) ecdsa_free(ecdsa_generate()); fprintf(stderr, "%17.2lf op/s\n", rate); key1 = ecdsa_generate(); key2 = ecdsa_generate(); // Ed25519 signatures fprintf(stderr, "Ed25519 sign for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) if(!ecdsa_sign(key1, buf1, 256, buf2)) return 1; fprintf(stderr, "%20.2lf op/s\n", rate); fprintf(stderr, "Ed25519 verify for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) if(!ecdsa_verify(key1, buf1, 256, buf2)) { fprintf(stderr, "Signature verification failed\n"); return 1; } fprintf(stderr, "%18.2lf op/s\n", rate); ecdh1 = ecdh_generate_public(buf1); fprintf(stderr, "ECDH for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) { ecdh2 = ecdh_generate_public(buf2); if(!ecdh2) return 1; if(!ecdh_compute_shared(ecdh2, buf1, buf3)) return 1; } fprintf(stderr, "%28.2lf op/s\n", rate); ecdh_free(ecdh1); // SPTPS authentication phase int fd[2]; if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); return 1; } struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}}; fprintf(stderr, "SPTPS/TCP authenticate for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) { sptps_start(&sptps1, fd + 0, true, false, key1, key2, "sptps_speed", 11, send_data, receive_record); sptps_start(&sptps2, fd + 1, false, false, key2, key1, "sptps_speed", 11, send_data, receive_record); while(poll(pfd, 2, 0)) { if(pfd[0].revents) receive_data(&sptps1); if(pfd[1].revents) receive_data(&sptps2); } sptps_stop(&sptps1); sptps_stop(&sptps2); } fprintf(stderr, "%10.2lf op/s\n", rate * 2); // SPTPS data sptps_start(&sptps1, fd + 0, true, false, key1, key2, "sptps_speed", 11, send_data, receive_record); sptps_start(&sptps2, fd + 1, false, false, key2, key1, "sptps_speed", 11, send_data, receive_record); while(poll(pfd, 2, 0)) { if(pfd[0].revents) receive_data(&sptps1); if(pfd[1].revents) receive_data(&sptps2); } fprintf(stderr, "SPTPS/TCP transmit for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) { if(!sptps_send_record(&sptps1, 0, buf1, 1451)) abort(); receive_data(&sptps2); } rate *= 2 * 1451 * 8; if(rate > 1e9) fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); else if(rate > 1e6) fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); else if(rate > 1e3) fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); sptps_stop(&sptps1); sptps_stop(&sptps2); // SPTPS datagram authentication phase close(fd[0]); close(fd[1]); if(socketpair(AF_UNIX, SOCK_DGRAM, 0, fd)) { fprintf(stderr, "Could not create a UNIX socket pair: %s\n", sockstrerror(sockerrno)); return 1; } fprintf(stderr, "SPTPS/UDP authenticate for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) { sptps_start(&sptps1, fd + 0, true, true, key1, key2, "sptps_speed", 11, send_data, receive_record); sptps_start(&sptps2, fd + 1, false, true, key2, key1, "sptps_speed", 11, send_data, receive_record); while(poll(pfd, 2, 0)) { if(pfd[0].revents) receive_data(&sptps1); if(pfd[1].revents) receive_data(&sptps2); } sptps_stop(&sptps1); sptps_stop(&sptps2); } fprintf(stderr, "%10.2lf op/s\n", rate * 2); // SPTPS datagram data sptps_start(&sptps1, fd + 0, true, true, key1, key2, "sptps_speed", 11, send_data, receive_record); sptps_start(&sptps2, fd + 1, false, true, key2, key1, "sptps_speed", 11, send_data, receive_record); while(poll(pfd, 2, 0)) { if(pfd[0].revents) receive_data(&sptps1); if(pfd[1].revents) receive_data(&sptps2); } fprintf(stderr, "SPTPS/UDP transmit for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) { if(!sptps_send_record(&sptps1, 0, buf1, 1451)) abort(); receive_data(&sptps2); } rate *= 2 * 1451 * 8; if(rate > 1e9) fprintf(stderr, "%14.2lf Gbit/s\n", rate / 1e9); else if(rate > 1e6) fprintf(stderr, "%14.2lf Mbit/s\n", rate / 1e6); else if(rate > 1e3) fprintf(stderr, "%14.2lf kbit/s\n", rate / 1e3); sptps_stop(&sptps1); sptps_stop(&sptps2); // Clean up close(fd[0]); close(fd[1]); ecdsa_free(key1); ecdsa_free(key2); crypto_exit(); return 0; }
/* * This function executes in signal handler context */ static void timerhandler(int whatever){ // printf("timer tick\n"); if (clock_state == TIMER_STOPPED) return; long invalbuf[NUM_PAGES]; int numinval = 0; int posval; clock_stop(); for (int i = 0; i < NumNode; ++i){ numinval = 0; for (int curr = activehead, last = curr;curr != -1; last = curr,curr = req_queues[curr].next_active){ if (curr == activehead){ last = curr; } if (curr_owners[curr] != i){ continue; } q_dta_t* the_queue = &(req_queues[curr]); if (the_queue->update_pending){ continue; } if (!the_queue->num_writers) continue; if (popped[curr]) continue; //better be true assert(the_queue->num_writers); qaddr = pagenum_to_addr(dsm_heaptop, curr, dsm_pagesize); int sessionfd = pop_queue(the_queue); popped[curr] = 1; if (!READ_REQ(sessionfd)){ the_queue->num_writers--; //was writing; need to wait for update if (the_queue->listlen && !the_queue->num_writers){ for (int i = 0;i < the_queue->listlen;i++){ the_queue->num_parallel_readers++; } } the_queue->update_pending = 1; }else{ if (the_queue->num_parallel_readers > 0){ //read requests granted before any writers came along //always at front of queue the_queue->num_parallel_readers --; } if (the_queue->listlen && !the_queue->num_parallel_readers){ int nextsessionfd = queue_top(the_queue); dsm_send(0, dsm_pagesize, SERVER_PAGE,(char*)pagenum_to_addr(dsm_heaptop,curr,dsm_pagesize) , ABS(nextsessionfd)); } } if ((!the_queue->listlen) || ABS(queue_top(the_queue)) != nid_to_sessionfd[i]){ invalbuf[numinval++] = curr * dsm_pagesize + dsm_heaptop; } if (the_queue->listlen){ //transfer ownership int tmp; posval = queue_top(the_queue); curr_owners[curr] = (short)(long)hash_get((void*)(long)ABS(posval),sessionfd_to_nid,&tmp); assert(tmp); }else{ curr_owners[curr] = -1; } if (!the_queue->num_writers){ if (the_queue->listlen){ the_queue->q_state = QUEUE_READERS; }else{ the_queue->q_state = QUEUE_EMPTY; } //take off the active list if (curr == last){ //delete from head activehead = req_queues[curr].next_active; }else{ req_queues[last].next_active = req_queues[curr].next_active; curr = last; } } } //TODO: send invalidation message to client if (numinval) { //printf("about to send %d inv to %d\n",numinval, nid_to_sessionfd[i]); dsm_send(0, sizeof(long)*numinval,SERVER_INVALIDATE, (char*)invalbuf, nid_to_sessionfd[i]); } } if (activehead != -1){ clock_start(); } our_memset (popped, 0, sizeof(char)*NUM_PAGES); //printf("END timer tick\n"); }
void queue_for_page(int sessionfd, long pagenum, int RW){ block_signal(SIGALRM); q_dta_t* the_queue = &(req_queues[pagenum]); assert(the_queue->num_parallel_readers <= the_queue->listlen); int make_active = 0; qaddr = pagenum_to_addr(dsm_heaptop, pagenum, dsm_pagesize); add_to_queue(RW*sessionfd, the_queue); if (RW == QUEUE_READ){ switch (the_queue->q_state){ case QUEUE_EMPTY: { int found; curr_owners[pagenum] = (short)(long)hash_get((void*)(long)sessionfd, sessionfd_to_nid,&found); assert(found); the_queue->q_state = QUEUE_READERS; if (!the_queue->update_pending){ long pagebegin = pagenum_to_addr(dsm_heaptop,pagenum, dsm_pagesize); dsm_send(0,dsm_pagesize,SERVER_PAGE,(char*)pagebegin,sessionfd); } the_queue->num_parallel_readers = 1; break; } case QUEUE_WRITERS: { break; } case QUEUE_READERS: { if (!the_queue->update_pending){ long pagebegin = pagenum_to_addr(dsm_heaptop,pagenum, dsm_pagesize); dsm_send(0,dsm_pagesize,SERVER_PAGE,(char*)pagebegin,sessionfd); } the_queue->num_parallel_readers++; break; } default:break; } }else{ the_queue->num_writers ++; switch (the_queue->q_state){ case QUEUE_EMPTY: { int found; curr_owners[pagenum] = (short)(long)hash_get((void*)(long)sessionfd, sessionfd_to_nid,&found); assert(found); the_queue->q_state = QUEUE_WRITERS; make_active = 1; if (!the_queue->update_pending){ long pagebegin = pagenum_to_addr(dsm_heaptop,pagenum, dsm_pagesize); dsm_send(0,dsm_pagesize,SERVER_PAGE,(char*)pagebegin,sessionfd); } break; } case QUEUE_WRITERS: { break; } case QUEUE_READERS: { the_queue->q_state = QUEUE_WRITERS; make_active = 1; break; } default:break; } } if (make_active){ req_queues[pagenum].next_active = activehead; activehead = pagenum; clock_start(); } unblock_signal(SIGALRM); }