void iiInit(FILE* file) { yyset_in(file); gint i; for(i=0; i < NUM_TRAC_STATEMENTS; i++) { statementsSucceed[i] = 0; statementsFail[i] = 0; } fileList = NULL; dirList = NULL; timing_init(); ast_init(); var_init(); //groups_init(); }
void timing_basic_alltoall_nelements( int DIM1, int procs, int loop, char* testname, MPI_Comm local_communicator) { float* send_array; float* recv_array; int myrank; int base, typesize, bytes, i; char method[50]; send_array = malloc( DIM1 * procs * sizeof(float)); recv_array = malloc( DIM1 * procs * sizeof(float)); MPI_Comm_rank( local_communicator, &myrank ); base = myrank * DIM1 + 1; utilities_fill_unique_array_1D_float( &send_array[0], DIM1, base ); if ( myrank == 0 ) { snprintf(method, 50, "reference"); MPI_Type_size( MPI_FLOAT, &typesize ); bytes = typesize * DIM1 * procs; timing_init( testname, &method[0], bytes ); } for( i=0 ; i<loop ; i++ ) { MPI_Alltoall(&send_array[0], DIM1, MPI_FLOAT, &recv_array[0], DIM1, MPI_FLOAT, local_communicator ); MPI_Alltoall(&recv_array[0], DIM1, MPI_FLOAT, &send_array[0], DIM1, MPI_FLOAT, local_communicator ); if ( myrank == 0 ) { timing_record(3); } } if ( myrank == 0 ) { timing_print( 1 ); } free(send_array); free(recv_array); }
void timing_basic_ping_pong_nelements( int DIM1, int loop, char* testname, MPI_Comm local_communicator) { float* array; int myrank; int base, typesize, bytes, i; char method[50]; array = malloc( DIM1 * sizeof(float)); MPI_Comm_rank( local_communicator, &myrank ); base = myrank * DIM1 + 1; utilities_fill_unique_array_1D_float( &array[0], DIM1, base ); if ( myrank == 0 ) { snprintf(&method[0], 50, "reference"); MPI_Type_size( MPI_FLOAT, &typesize ); bytes = typesize * DIM1; timing_init( testname, &method[0], bytes ); } for( i=0 ; i<loop ; i++ ){ if ( myrank == 0 ) { MPI_Send( &array[0], DIM1, MPI_FLOAT, 1, itag, local_communicator ); MPI_Recv( &array[0], DIM1, MPI_FLOAT, 1, itag, local_communicator, MPI_STATUS_IGNORE ); timing_record(3); } else { MPI_Recv( &array[0], DIM1, MPI_FLOAT, 0, itag, local_communicator, MPI_STATUS_IGNORE ); MPI_Send( &array[0], DIM1, MPI_FLOAT, 0, itag, local_communicator ); } } if ( myrank == 0 ) { timing_print( 1 ); } free(array); }
int main (int argc, char **argv) { char *ch; if (argc != 2) { fputs("Invalid number of arguments\n", stderr); fputs("usage: hspwrap EXEFILE\n", stderr); exit(EXIT_FAILURE); } ch = getenv("HSP_BCAST_CHUNK_SIZE"); if (ch) { sscanf(ch, "%zu", &bcast_chunk_size); } else { bcast_chunk_size = 4L << 20; } ch = getenv("HSP_INPUT_FORMAT"); if (!ch || ch[0] == '\0' || ch[0] == 'l') { info("Input format: Lines\n"); input_fmt = 'l'; } else if (ch[0] == 'f') { info("Input format: FASTA\n"); input_fmt = 'f'; } else { fputs("Invalid input format specified\n", stderr); exit(EXIT_FAILURE); } // Pre-fork process pool (even on master) #ifndef TIMING_MODE sleep(1); pool_ctl = process_pool_fork(); trace("Process pool created.\n"); sleep(1); #endif // Initialize MPI int rank, ranks; if (MPI_Init(NULL, NULL) != MPI_SUCCESS) { fprintf(stderr, "Error initialize MPI.\n"); return EXIT_FAILURE; } MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &ranks); trace("MPI Initialized.\n"); // Initialize our state timing_init(&timing); if (rank) { slave_init(rank, ranks-1, NUM_PROCS); } else { print_banner_slant(stderr); master_init(); } // Broadcast binary files first if (rank) { slave_broadcast_work_file("exefile"); } else { master_broadcast_file(getenv("HSP_EXEFILE")); } // Distribute DB files MPI_Barrier(MPI_COMM_WORLD); timing_record(&timing.db_start); char *dbdir = getenv("HSP_DBDIR"); char *dbfiles = strdup(getenv("HSP_DBFILES")); char *fn, path[PATH_MAX]; for (fn = strtok(dbfiles, ":"); fn; fn = strtok(NULL, ":")) { snprintf(path, sizeof(path), "%s/%s", dbdir, fn); if (rank) { timing.db_kbytes += slave_broadcast_shared_file(path)/1024; } else { timing.db_kbytes += master_broadcast_file(path)/1024; } } free(dbfiles); MPI_Barrier(MPI_COMM_WORLD); timing_record(&timing.db_end); #ifdef TIMING_MODE if (!rank) { timing_print(&timing); } MPI_Finalize(); return 0; #endif // FIXME: The order of things is generally wrong. Should be: // Fork Forker, MPI_Init, PS Ctl, EXE/DB distro, forking, main loop #if 0 // Now print some stats if (rank) { MPI_Barrier(MPI_COMM_WORLD); printf("Rank %d Processes: %d", rank, ps_ctl->nprocesses); printf(" Process ID: %d", getpid()); printf(" Files: %d (", ps_ctl->ft.nfiles); for (i=0; i<ps_ctl->ft.nfiles; ++i) { printf("%s, ", ps_ctl->ft.file[i].name); } puts(")"); } else { printf("Ranks: %d\n\n", ranks); MPI_Barrier(MPI_COMM_WORLD); } #endif if (rank) { slave_main(argv[1]); } else { master_main(ranks-1); timing_print(&timing); } return 0; }
static void sign_and_verify(const bench_options_t* options) { static const uint8_t m[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}; timing_and_size_t* timings_fis = calloc(options->iter, sizeof(timing_and_size_t)); const size_t max_signature_size = picnic_signature_size(options->params); if (!max_signature_size) { printf("Failed to create Picnic instance.\n"); return; } uint8_t sig[PICNIC_MAX_SIGNATURE_SIZE]; timing_context_t ctx; timing_init(&ctx); for (unsigned int i = 0; i != options->iter; ++i) { #ifndef WITH_DETAILED_TIMING timing_and_size_t* timing_and_size; uint64_t start_time = timing_read(&ctx); #endif timing_and_size = &timings_fis[i]; timing_and_size->max_size = max_signature_size; picnic_privatekey_t private_key; picnic_publickey_t public_key; if (picnic_keygen(options->params, &public_key, &private_key)) { printf("Failed to create key.\n"); break; } #ifndef WITH_DETAILED_TIMING uint64_t tmp_time = timing_read(&ctx); timing_and_size->keygen = tmp_time - start_time; start_time = timing_read(&ctx); #endif size_t siglen = max_signature_size; if (!picnic_sign(&private_key, m, sizeof(m), sig, &siglen)) { #ifndef WITH_DETAILED_TIMING tmp_time = timing_read(&ctx); timing_and_size->sign = tmp_time - start_time; timing_and_size->size = siglen; start_time = timing_read(&ctx); #endif if (picnic_verify(&public_key, m, sizeof(m), sig, siglen)) { printf("picnic_verify: failed\n"); } #ifndef WITH_DETAILED_TIMING tmp_time = timing_read(&ctx); timing_and_size->verify = tmp_time - start_time; #endif } else { printf("picnic_sign: failed\n"); } } #ifdef VERBOSE printf("Picnic signature:\n\n"); #endif timing_close(&ctx); print_timings(timings_fis, options->iter); OQS_MEM_insecure_free(timings_fis); }
///////////////////////////////////////////////////////////////// // This initialises the stuff. We support supplying port as // a command line argument. // MODULE_EXPORT int stv5730_init (Driver *drvthis) { PrivateData *p; int i; /* Allocate and store private data */ p = (PrivateData *) calloc(1, sizeof(PrivateData)); if (p == NULL) return -1; if (drvthis->store_private_ptr(drvthis, p)) return -1; /* initialize private data */ p->port = LPTPORT; p->charattrib = STV5730_ATTRIB; p->flags = 0; p->framebuf = NULL; /* Read config file */ /* What port to use */ p->port = drvthis->config_get_int(drvthis->name, "Port", 0, LPTPORT); /* End of config file parsing */ if (timing_init() == -1) { report(RPT_ERR, "%s: timing_init() failed (%s)", drvthis->name, strerror(errno)); return -1; } // Initialize the Port and the stv5730 if (port_access(p->port) || port_access(p->port + 1)) { report(RPT_ERR, "%s: cannot get IO-permission for 0x%03X! Are we running as root?", drvthis->name, p->port); return -1; } if (stv5730_detect(p->port)) { report(RPT_ERR, "%s: no STV5730 hardware found at 0x%03X ", drvthis->name, p->port); return -1; } port_out(p->port, 0); // Reset the STV5730 stv5730_write16bit(p->port, p->flags, 0x3000); stv5730_write16bit(p->port, p->flags, 0x3000); stv5730_write16bit(p->port, p->flags, 0x00db); stv5730_write16bit(p->port, p->flags, 0x1000); // Setup Mode + Control Register for video detection stv5730_write16bit(p->port, p->flags, STV5730_REG_MODE); stv5730_write16bit(p->port, p->flags, 0x1576); stv5730_write16bit(p->port, p->flags, STV5730_REG_CONTROL); stv5730_write16bit(p->port, p->flags, 0x1FF4); report(RPT_INFO, "%s: detecting video signal: ", drvthis->name); usleep (50000); if (stv5730_is_mute(p->port)) { report(RPT_INFO, "%s: no video signal found; using full page mode", drvthis->name); // Setup Mode + Control for full page mode p->charattrib = STV5730_ATTRIB; stv5730_write16bit(p->port, p->flags, STV5730_REG_MODE); stv5730_write16bit(p->port, p->flags, 0x15A6); stv5730_write16bit(p->port, p->flags, STV5730_REG_CONTROL); #ifdef PAL stv5730_write16bit(p->port, p->flags, 0x1FD5); #endif #ifdef NTSC stv5730_write16bit(p->port, p->flags, 0x1ED4); #endif } else { report(RPT_INFO, "%s: video signal found, using mixed mode (B&W)", drvthis->name); // Setup Mode + Control for mixed mode, disable color p->charattrib = 0; stv5730_write16bit(p->port, p->flags, STV5730_REG_MODE); stv5730_write16bit(p->port, p->flags, 0x1576); stv5730_write16bit(p->port, p->flags, STV5730_REG_CONTROL); #ifdef PAL stv5730_write16bit(p->port, p->flags, 0x1DD4); #endif #ifdef NTSC stv5730_write16bit(p->port, p->flags, 0x1CF4); #endif } // Position Register stv5730_write16bit(p->port, p->flags, STV5730_REG_POSITION); stv5730_write16bit(p->port, p->flags, 0x1000 + 64 * 30 + 30); // Color Register stv5730_write16bit(p->port, p->flags, STV5730_REG_COLOR); stv5730_write16bit(p->port, p->flags, 0x1000 + (STV5730_COL_SBACK << 9) + (STV5730_COL_CBORD << 6) + STV5730_COL_CBACK); // Zoom Register: Zoom first line stv5730_write16bit(p->port, p->flags, STV5730_REG_ZOOM); stv5730_write16bit(p->port, p->flags, 0x1000 + 4); // Set the Row Attributes for (i = 0; i <= 10; i++) { stv5730_write16bit(p->port, p->flags, 0x00C0 + i); stv5730_write16bit(p->port, p->flags, 0x10C0); } // Allocate our own framebuffer p->framebuf = malloc(STV5730_WID * STV5730_HGT); if (p->framebuf == NULL) { report(RPT_ERR, "%s: unable to allocate framebuffer", drvthis->name); stv5730_close(drvthis); return -1; } // clear screen memset(p->framebuf, 0, STV5730_WID * STV5730_HGT); report(RPT_DEBUG, "%s: init() done", drvthis->name); return 0; }
int main() { dispatch_msg *msg; timing_init(); //Initiate the process grid pgrid_init(); while(1) { //Receive the dispatch message from the master-process dispatch_reset(); dispatch_recv(&msg); //Handle the message switch(msg->type) { case BH_CLUSTER_DISPATCH_INIT: { char *name = msg->payload; check_error(exec_init(name),__FILE__,__LINE__); break; } case BH_CLUSTER_DISPATCH_SHUTDOWN: { check_error(exec_shutdown(),__FILE__,__LINE__); return 0; } case BH_CLUSTER_DISPATCH_EXTMETHOD: { bh_opcode opcode = *((bh_opcode *)msg->payload); char *name = msg->payload+sizeof(bh_opcode); check_error(exec_extmethod(name, opcode),__FILE__,__LINE__); break; } case BH_CLUSTER_DISPATCH_EXEC: { //Get the size of the the serialized BhIR bh_intp bhir_size = *((bh_intp*) msg->payload); //Deserialize the BhIR bh_ir bhir = bh_ir(((char*)msg->payload)+sizeof(bh_intp), bhir_size); //The number of new arrays bh_intp *noa = (bh_intp *)(((char*)msg->payload)+sizeof(bh_intp)+bhir_size); //The list of new arrays dispatch_array *darys = (dispatch_array*)(noa+1); //number of new arrays //Insert the new array into the array store and the array maps std::stack<bh_base*> base_darys; for(bh_intp i=0; i < *noa; ++i) { bh_base *ary = dispatch_new_slave_array(&darys[i].ary, darys[i].id); base_darys.push(ary); } //Receive the dispatched array-data from the master-process dispatch_array_data(base_darys); //Update all instruction to reference local arrays for(uint64_t i=0; i < bhir.instr_list.size(); ++i) { bh_instruction *inst = &bhir.instr_list[i]; int nop = bh_noperands(inst->opcode); bh_view *ops = bh_inst_operands(inst); //Convert all instructon operands for(bh_intp j=0; j<nop; ++j) { if(bh_is_constant(&ops[j])) continue; bh_base *base = bh_base_array(&ops[j]); assert(dispatch_slave_exist((bh_intp)base)); bh_base_array(&ops[j]) = dispatch_master2slave((bh_intp)base); } } check_error(exec_execute(&bhir),__FILE__,__LINE__); break; } default: fprintf(stderr, "[VEM-CLUSTER] Slave (rank %d) " "received unknown message type\n", pgrid_myrank); MPI_Abort(MPI_COMM_WORLD,BH_ERROR); } } timing_finalize(); return BH_SUCCESS; }
/** * API: Initialize the driver. */ MODULE_EXPORT int sdeclcd_init(Driver *drvthis) { PrivateData *p; int i, j; /* * Compact version of big num character bitmaps. Stack each line * separately to visualize each char. */ static char bignum_bitmaps[] = { b___XXXX, b__XX___, b__XX___, b__XX___, b__XX___, b__XX___, b__XX___, b__XX___, b__XXXX_, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b__XX___, b__XX___, b__XX___, b__XX___, b__XX___, b__XX___, b__XX___, b___XXXX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b__XXXX_, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b__XXXXX, b_______, b_______, b_______, b_______, b_______, b_______, b__XXXXX, b__XXXX_, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b_____XX, b__XXXX_, b___XXXX, b__XX___, b__XX___, b__XX___, b__XX___, b__XX___, b__XX___, b___XXXX }; /* Allocate and store private data */ p = (PrivateData *) malloc(sizeof(PrivateData)); if (p == NULL) return -1; if (drvthis->store_private_ptr(drvthis, p)) return -1; /* Initialize private data and read config */ p->ccmode = standard; p->bklgt = BACKLIGHT_ON; p->bklgt_timer = SDEC_BKLT_DFT; p->bklgt_lasttime = time(NULL); p->hrbt_lasttime = time(NULL); p->hb_stus = HEARTBEAT_OFF; p->framebuf = (char *)malloc(SDEC_DISP_W * SDEC_DISP_H); p->framelcd = (char *)malloc(SDEC_DISP_W * SDEC_DISP_H); p->vbar_cg = (char *)malloc(SDEC_CELL_H * SDEC_NUM_CC); p->hbar_cg = (char *)malloc(SDEC_CELL_H * SDEC_NUM_CC); p->bignum_cg = (char *)bignum_bitmaps; if (NULL == p->framebuf || NULL == p->framelcd || NULL == p->vbar_cg || NULL == p->hbar_cg) { report(RPT_ERR, "%s: unable to allocate framebuffer", drvthis->name); return -1; } memset(p->framebuf, ' ', SDEC_DISP_W * SDEC_DISP_H); memset(p->framelcd, ' ', SDEC_DISP_W * SDEC_DISP_H); /* Prepare custom character bitmaps:vbar, hbar */ for (i = 0; i < SDEC_NUM_CC; i++) { for (j = 0; j < SDEC_CELL_H; j++) { /* Visualize this: */ p->vbar_cg[i * SDEC_CELL_H + SDEC_CELL_H - j - 1] = (j <= i) ? 0xFF : 0; p->hbar_cg[i * SDEC_CELL_H + j] = (~(0x0F >> i)) & 0x1F; } } p->bignum_cg = bignum_bitmaps; /* Initializes the scheduler, see timing.h */ timing_init(); /* Initialize access to the ports */ if (port_access_multiple(LPT_DEFAULT, 3)) { report(RPT_ERR, "%s: cannot get IO-permission for 0x%03X! Are we root?", drvthis->name, LPT_DEFAULT); return -1; } sdec_init(); return 0; }
/* 功能: 程序开始时初始化各个模块,启动相关的线程,instruction线程用于处理具体指令,timing线程管理定时器 返回: 0——成功;-1——失败 */ int global_init() { int ret = -1; if(-1==dir_exist_ensure(WORKSPACE_SURFIX)) return -1; setting_init(); if(-1==dir_exist_ensure(FIFO_DIR)) return -1; if(-1==socket_init()){ DEBUG("socket module init failed\n"); return -1; } if(-1==sqlite_init()){ DEBUG("sqlite module init failed\n"); return -1; } if(-1==timing_init()){ DEBUG("timer module init failed\n"); return -1; } if(-1==equipment_init()){ DEBUG("equipment array init failed\n"); return -1; } if(-1==instruction_init()){ DEBUG("instruction module init failed\n"); return -1; } if(-1==serial_int()){ DEBUG("serial module init failed\n"); return -1; } // only for database testing //DEBUG("getGlobalPara(version)=%d\n", getGlobalPara("version")); //~~~~~~~~~~create thread~~~~~~~~~~// typedef void*(*format)(void *); ///define function pointer of "void*(name)(void*)" pthread_t l_socketlinkthread; /// the file description of thread #if 0 pthread_attr_t l_attrthread; ///the attribute of thread size_t l_stacksize=1048576*1; ///set thread stack size ///start thread. pthread_attr_init(&l_attrthread); ///initialize attribute pthread_attr_setscope(&l_attrthread,PTHREAD_SCOPE_SYSTEM); ///set attribute binding pthread_attr_setdetachstate(&l_attrthread,PTHREAD_CREATE_DETACHED); ///set attribute detached pthread_attr_setstacksize(&l_attrthread,l_stacksize); ret=pthread_create(&l_socketlinkthread,&l_attrthread,(format)socketHandler,NULL); #else /* use default attr */ ret = pthread_create(&l_socketlinkthread,NULL,(format)instruction_mainloop,NULL); #endif if(0!=ret) { ERROROUT("thread instruction_mainloop create failed!"); return -1; } pthread_t timing_thread_id; ret = pthread_create(&timing_thread_id, NULL, (void *)timing_mainloop, NULL); if(0!=ret){ ERROROUT("thread timing_mainloop create failed\n"); } return 0; }