rng_type * rng_config_init_rng__(const rng_config_type * rng_config, rng_type * rng) { const char * seed_load = rng_config_get_seed_load_file( rng_config ); const char * seed_store = rng_config_get_seed_store_file( rng_config ); if (seed_load != NULL) { if (util_file_exists( seed_load)) { FILE * stream = util_fopen( seed_load , "r"); rng_fscanf_state( rng , stream ); fclose( stream ); } else { /* In the special case that seed_load == seed_store; we accept a seed_load argument pointing to a non-existant file. */ if (seed_store) { if (util_string_equal( seed_store , seed_load)) rng_init( rng , INIT_DEV_URANDOM ); else util_abort("%s: tried to load random seed from non-existing file:%s \n",__func__ , seed_load); } } } else rng_init( rng , INIT_DEV_URANDOM ); if (seed_store != NULL) { FILE * stream = util_mkdir_fopen( seed_store , "w"); rng_fprintf_state( rng , stream ); fclose( stream ); } return rng; }
void *dspio_init(void) { struct dspio_state *state; state = malloc(sizeof(struct dspio_state)); if (!state) return NULL; memset(&state->dma, 0, sizeof(struct dspio_dma)); state->input_running = state->pcm_input_running = state->lin_input_running = state->mic_input_running = state->output_running = state->dac_running = state->speaker = 0; state->dma.dsp_fifo_enabled = 1; rng_init(&state->fifo_in, DSP_FIFO_SIZE, 2); rng_init(&state->fifo_out, DSP_FIFO_SIZE, 2); rng_init(&state->midi_fifo_in, MIDI_FIFO_SIZE, 1); rng_init(&state->midi_fifo_out, MIDI_FIFO_SIZE, 1); state->i_handle = pcm_register_player(&player, state); pcm_init(); pcm_set_volume_cb(dspio_get_volume); pcm_set_connected_cb(dspio_is_connected); state->dac_strm = pcm_allocate_stream(1, "SB DAC", (void*)MC_VOICE); pcm_set_flag(state->dac_strm, PCM_FLAG_RAW); state->dma_strm = pcm_allocate_stream(2, "SB DMA", (void*)MC_VOICE); pcm_set_flag(state->dma_strm, PCM_FLAG_SLTS); midi_init(); return state; }
int sec_init(void) { int ret = 0; #ifdef CONFIG_PHYS_64BIT ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR; uint32_t mcr = sec_in32(&sec->mcfgr); sec_out32(&sec->mcfgr, mcr | 1 << MCFGR_PS_SHIFT); #endif ret = jr_init(); if (ret < 0) { printf("SEC initialization failed\n"); return -1; } if (get_rng_vid() >= 4) { if (rng_init() < 0) { printf("RNG instantiation failed\n"); return -1; } printf("SEC: RNG instantiated\n"); } return ret; }
void xs_rng_get(xsMachine *the) { size_t n = xsToInteger(xsArg(0)); uint8_t *bp, *bufend; uint8_t i, j, t; if (!rng_inited) { /* use srand */ #define DEFAULT_SEED_SIZE 16 uint8_t seed[DEFAULT_SEED_SIZE]; for (i = 0; i < DEFAULT_SEED_SIZE; i++) seed[i] = ((uint64_t)c_rand() * 256) / C_RAND_MAX; rng_init(seed, DEFAULT_SEED_SIZE); rng_inited++; } xsResult = xsArrayBuffer(NULL, n); bp = xsToArrayBuffer(xsResult); for (i = j = 0, bufend = bp + n; bp < bufend;) { ++i; j += rng_state[i]; t = rng_state[i]; rng_state[i] = rng_state[j]; rng_state[j] = t; t = rng_state[i] + rng_state[j]; *bp++ = rng_state[t]; } }
static void arena_weighted_mbind(void *arena, size_t arena_size, uint16_t *weights, size_t nr_weights) { /* compute cumulative sum for weights * cumulative sum starts at -1 * the method for determining a hit on a weight i is when the generated * random number (modulo sum of weights) <= weights_cumsum[i] */ int64_t weights_cumsum[nr_weights]; weights_cumsum[0] = weights[0] - 1; for (unsigned int i = 1; i < nr_weights; i++) { weights_cumsum[i] = weights_cumsum[i-1] + weights[i]; } const int32_t weight_sum = weights_cumsum[nr_weights-1]+1; const int pagesize = getpagesize(); uint64_t mask = 0; char *q = (char *)arena + arena_size; rng_init(1); for (char *p = arena; p < q; p += pagesize) { uint32_t r = rng_int(1<<31) % weight_sum; unsigned int node; for (node = 0; node < nr_weights; node++) { if (weights_cumsum[node] >= r) { break; } } mask = 1 << node; if (mbind(p, pagesize, MPOL_BIND, &mask, nr_weights, MPOL_MF_STRICT)) { perror("mbind"); exit(1); } *p = 0; } }
int main(int argc, char**argv){ unsigned int seed=19650218, count=100000,threadid=0,i; RandType ran0[RAND_BUF_LEN] __attribute__ ((aligned(16))); RandType ran1[RAND_BUF_LEN] __attribute__ ((aligned(16))); if(argc>=2) count=atoi(argv[1]); if(argc>=3) seed=atoi(argv[2]); if(count==0 || seed==0 || argc==1){ /*when atoi returned error*/ usage(argv[0]); exit(0); } if(seed<0) seed=time(NULL); #pragma omp parallel private(ran0,ran1,threadid) { #ifdef _OPENMP threadid=omp_get_thread_num(); #endif rng_init(ran0,ran1,(unsigned int *)&seed,threadid); #pragma omp for for(i=0;i<count;i++){ genrand(threadid,i,ran0,ran1); } } return 0; }
void machine_init(struct fnode * dev) { # if CONFIG_SYS_CLOCK == 48000000 rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_48MHZ]); # elif CONFIG_SYS_CLOCK == 84000000 rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_84MHZ]); # elif CONFIG_SYS_CLOCK == 120000000 rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_120MHZ]); # elif CONFIG_SYS_CLOCK == 168000000 rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); # else #error No valid clock speed selected #endif #ifdef CONFIG_DEVGPIO gpio_init(dev, gpio_addrs, NUM_GPIOS); #endif #ifdef CONFIG_DEVUART uart_init(dev, uart_addrs, NUM_UARTS); #endif #ifdef CONFIG_RNG rng_init(dev, rng_addrs, NUM_RNGS); #endif #ifdef CONFIG_DEVSTM32SDIO stm32_sdio_rcc_init(); stm32_sdio_init(dev); #endif #ifdef CONFIG_DEVSTMETH gpio_clear(GPIOE,GPIO2); /* Clear ETH nRESET pin */ gpio_set(GPIOE,GPIO2); /* Set ETH nRESET pin */ #endif }
int main (int argc, char * argv[]) { bool restart; unsigned long int particles_n; if (argc < 2) { particles_n = NUMBER_OF_PARTICLES; } else { errno = 0; particles_n = strtoul(argv[1], NULL, 0); if (errno) { perror(__func__); exit(EXIT_FAILURE); } } n = particles_n; px = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); py = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); vx = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); vy = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); m = align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING); if (px == NULL || py == NULL || vx == NULL || vy == NULL || m == NULL) { perror("main"); exit(EXIT_FAILURE); } draw_init(SCREEN_WIDTH, SCREEN_HEIGHT, FRAME_RATE, n); physics_init(n); rng_init(); do { draw_reset(n); physics_reset(n); restart = main_loop(); } while (restart); rng_free(); physics_free(); draw_free(); align_free(m); align_free(vy); align_free(vx); align_free(py); align_free(px); exit(EXIT_SUCCESS); }
rust_sched_loop::rust_sched_loop(rust_scheduler *sched, int id, bool killed) : _log(this), id(id), should_exit(false), cached_c_stack(NULL), extra_c_stack(NULL), cached_big_stack(NULL), extra_big_stack(NULL), dead_task(NULL), killed(killed), pump_signal(NULL), kernel(sched->kernel), sched(sched), log_lvl(log_debug), min_stack_size(kernel->env->min_stack_size), local_region(false, kernel->env->detailed_leaks, kernel->env->poison_on_free), // FIXME #2891: calculate a per-scheduler name. name("main") { LOGPTR(this, "new dom", (uintptr_t)this); rng_init(&rng, kernel->env->rust_seed, NULL, 0); if (!tls_initialized) init_tls(); }
int gen_example() { const int n = 3; /* const char *str = "A A A B A B B A";*/ /* const int genlen = 20;*/ const char *str = "A B C"; const int genlen = 10; wordlist_t *wl; ngram_t *ng; int ngsize; wl = lex(str, strlen(str)); ng = process(wl, n, &ngsize); rng_state_t rs; const int seed = 1234; rng_prepare(&rs); rng_set_type(&rs, RNG_TYPE_MT); rng_init(&rs, seed); char *ret; int retlen; retlen = ngram_gen(n, &rs, ng, ngsize, genlen, &ret); printf("%s\n", ret); free(ret); return 0; }
extern "C" CDECL void * rand_new_seeded(uint8_t* seed, size_t seed_size) { assert(seed != NULL); rust_rng *rng = (rust_rng *) malloc(sizeof(rust_rng)); assert(rng != NULL && "rng alloc failed"); rng_init(rng, NULL, seed, seed_size); return rng; }
void uts_initRoot(Node * root, int type) { root->height = 0; root->numChildren = -1; // means not yet determined rng_init(root->state.state, rootId); //printf("Root node of type %d at %p\n",type, root); }
void uts_initRoot(Node * root) { root->height = 0; root->numChildren = -1; // means not yet determined rng_init(root->state.state, rootId); bots_message("Root node at %p\n", root); }
int main(int argc , char ** argv) { rng_type * rng = rng_alloc( MZRAN , INIT_DEFAULT ); { int val1 = rng_get_int( rng , MAX_INT); int val2 = rng_get_int( rng , MAX_INT); test_assert_int_not_equal( val1 , val2 ); rng_init( rng , INIT_DEFAULT ); val2 = rng_get_int( rng , MAX_INT ); test_assert_int_equal( val1 , val2 ); } { int val2 , val1; int state_size = rng_state_size( rng ); char * buffer1 = util_calloc( state_size , sizeof * buffer1 ); char * buffer2 = util_calloc( state_size , sizeof * buffer2 ); test_assert_int_not_equal( state_size , 0 ); test_assert_int_equal( state_size , MZRAN_STATE_SIZE ); rng_init( rng , INIT_DEFAULT ); rng_get_state( rng , buffer1 ); val1 = rng_get_int( rng , MAX_INT); val2 = rng_get_int( rng , MAX_INT); test_assert_int_not_equal( val1 , val2 ); rng_set_state( rng , buffer1 ); val2 = rng_get_int( rng , MAX_INT); test_assert_int_equal( val1 , val2 ); rng_init( rng , INIT_DEFAULT ); rng_get_state( rng , buffer2 ); test_assert_mem_equal( buffer1 , buffer2 , state_size ); val2 = rng_get_int( rng , MAX_INT); rng_get_state( rng , buffer2 ); test_assert_mem_not_equal( buffer1 , buffer2 , state_size ); free( buffer1 ); free( buffer2 ); } rng_free( rng ); exit(0); }
extern "C" CDECL void * rand_new_seeded(uint8_t* seed, size_t seed_size) { rust_task *task = rust_get_current_task(); rust_rng *rng = (rust_rng *) task->malloc(sizeof(rust_rng), "rand_new_seeded"); if (!rng) { task->fail(); return NULL; } rng_init(task->kernel, rng, seed, seed_size); return rng; }
int main(void) { gpio_init(); rng_init(); clock_init(); radio_init(); average_init(); while (true){ sniffer_loop(); } }
void xs_rng_init(xsMachine *the) { int i; for (i = 0; i < 256; i++) rng_state[i] = i; if (xsToInteger(xsArgc) > 0 && xsTest(xsArg(0))) { uint8_t *seed = xsToArrayBuffer(xsArg(0)); size_t seedsize = xsGetArrayBufferLength(xsArg(0)); rng_init(seed, seedsize); } rng_inited++; }
int main(int argc, char *argv[]){ parse_args(argc, argv); size_t remaining = option_bytes; sosemanuk_run_context ctx; u8 *bytes = mmap(NULL, BUFFER_BYTES, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); rng_init(&ctx, option_seed); for(;option_bytes == 0 || remaining >= BUFFER_BYTES;){ sosemanuk_prng(&ctx, bytes, BUFFER_BYTES); remaining -= write(1, bytes, BUFFER_BYTES); } if (remaining){ sosemanuk_prng(&ctx, bytes, remaining); remaining = write(1, bytes, remaining); } return 0; }
/* * Creates and initializes a new queue */ struct queue * queue_new() { struct queue *queue; queue = (struct queue *)calloc(1, sizeof(struct queue)); queue->head = (struct queue_item *)calloc(1, sizeof(struct queue_item)); // Create the head item and make the queue circular (head points to itself) queue->head->next = queue->head; queue->head->prev = queue->head; queue->head->shuffle_next = queue->head; queue->head->shuffle_prev = queue->head; rng_init(&queue->shuffle_rng); return queue; }
void machine_init(struct fnode * dev) { # if CONFIG_SYS_CLOCK == 216000000 rcc_clock_setup_hse_3v3(&hse_25mhz_3v3[CLOCK_3V3_216MHZ]); # else #error No valid clock speed selected for STM32F729 Discovery #endif #ifdef CONFIG_DEVGPIO gpio_init(dev, gpio_addrs, NUM_GPIOS); #endif #ifdef CONFIG_DEVUART uart_init(dev, uart_addrs, NUM_UARTS); #endif #ifdef CONFIG_RNG rng_init(dev, rng_addrs, NUM_RNGS); #endif }
void machine_init(struct fnode * dev) { # if CONFIG_SYS_CLOCK == 168000000 rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); # elif CONFIG_SYS_CLOCK == 84000000 rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_84MHZ]); # elif CONFIG_SYS_CLOCK == 48000000 rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_48MHZ]); # else #error No valid clock speed selected for STM32F429 Discovery #endif #ifdef CONFIG_DEVGPIO gpio_init(dev, gpio_addrs, NUM_GPIOS); #endif #ifdef CONFIG_DEVUART uart_init(dev, uart_addrs, NUM_UARTS); #endif #ifdef CONFIG_RNG rng_init(dev, rng_addrs, NUM_RNGS); #endif }
/* ************************************************** */ int do_init(void) { if (das_init() || /* das */ sodas_init() || /* sodas */ spadas_init() || /* spadas */ hadas_init() || /* hadas */ rng_init() || /* rng */ timer_init() || /* timer */ bundle_init() || /* bundle */ entity_init() || /* entity */ monitor_init() || /* monitor */ measure_init() || /* mesure */ medium_init() || /* medium */ mobility_init() || /* mobility */ modulation_init() || /* modulation */ noise_init() || /* noise */ node_init() || /* node */ packet_init() || /* packet */ scheduler_init()) { /* scheduler */ return -1; } return 0; }
int main_gen(const int n, const char *str, const int genlen, const int seed) { wordlist_t *wl; ngram_t *ng; int ngsize; wl = lex(str, strlen(str)); ng = process(wl, n, &ngsize); rng_state_t rs; rng_prepare(&rs); rng_set_type(&rs, RNG_TYPE_MT); rng_init(&rs, seed); char *ret; int retlen; retlen = ngram_gen(n, &rs, ng, ngsize, genlen, &ret); printf("%s\n", ret); free(ret); return 0; }
void setup() { uint32 test; /* Set up the LED to blink */ pinMode(BOARD_GREEN_LED_PIN, OUTPUT); pinMode(BOARD_ORANGE_LED_PIN, OUTPUT); pinMode(BOARD_BLUE_LED_PIN, OUTPUT); pinMode(BOARD_RED_LED_PIN, OUTPUT); /* Turn on PWM on pin PWM_PIN */ // pinMode(PWM_PIN, PWM); // pwmWrite(PWM_PIN, 0x8000); /* Send a message out USART2 */ // Serial2.begin(9600); // Serial2.println("Hello world!"); /* Send a message out the usb virtual serial port */ //SerialUSB.println("Hello!"); rng_init(); rng_enable(); // togglePin(BOARD_BLUE_LED_PIN); while ( (test = rng_get_number()) < 3) { // if () togglePin(BOARD_BLUE_LED_PIN); /* if (check_PLL() >2) togglePin(BOARD_RED_LED_PIN); if (check_PLL() < 15) togglePin(BOARD_ORANGE_LED_PIN);*/ } }
/// \function rng() /// Return a 30-bit hardware generated random number. STATIC mp_obj_t pyb_rng_get(void) { if (RNGHandle.State == HAL_RNG_STATE_RESET) { rng_init(); } return mp_obj_new_int(HAL_RNG_GetRandomNumber(&RNGHandle) >> 2); }
/** * @brief The entry point of Naev. * * @param[in] argc Number of arguments. * @param[in] argv Array of argc arguments. * @return EXIT_SUCCESS on success. */ int main( int argc, char** argv ) { char buf[PATH_MAX]; /* Save the binary path. */ binary_path = strdup(argv[0]); /* Print the version */ LOG( " "APPNAME" v%s", naev_version(0) ); #ifdef GIT_COMMIT DEBUG( " git HEAD at " GIT_COMMIT ); #endif /* GIT_COMMIT */ /* Initializes SDL for possible warnings. */ SDL_Init(0); /* Initialize the threadpool */ threadpool_init(); /* Set up debug signal handlers. */ debug_sigInit(); /* Must be initialized before input_init is called. */ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { WARN("Unable to initialize SDL Video: %s", SDL_GetError()); return -1; } /* Get desktop dimensions. */ #if SDL_VERSION_ATLEAST(1,2,10) const SDL_VideoInfo *vidinfo = SDL_GetVideoInfo(); gl_screen.desktop_w = vidinfo->current_w; gl_screen.desktop_h = vidinfo->current_h; #else /* #elif SDL_VERSION_ATLEAST(1,2,10) */ gl_screen.desktop_w = 0; gl_screen.desktop_h = 0; #endif /* #elif SDL_VERSION_ATLEAST(1,2,10) */ /* We'll be parsing XML. */ LIBXML_TEST_VERSION xmlInitParser(); /* Input must be initialized for config to work. */ input_init(); conf_setDefaults(); /* set the default config values */ /* * Attempts to load the data path from datapath.lua * At this early point in the load process, the binary path * is the only place likely to be checked. */ conf_loadConfigPath(); /* Parse the user data path override first. */ conf_parseCLIPath( argc, argv ); /* Create the home directory if needed. */ if (nfile_dirMakeExist("%s", nfile_configPath())) WARN("Unable to create config directory '%s'", nfile_configPath()); /* Set the configuration. */ nsnprintf(buf, PATH_MAX, "%s"CONF_FILE, nfile_configPath()); #if HAS_UNIX /* TODO get rid of this cruft ASAP. */ int oldconfig = 0; if (!nfile_fileExists( buf )) { char *home, buf2[PATH_MAX]; home = SDL_getenv( "HOME" ); if (home != NULL) { nsnprintf( buf2, PATH_MAX, "%s/.naev/"CONF_FILE, home ); if (nfile_fileExists( buf2 )) oldconfig = 1; } } #endif /* HAS_UNIX */ conf_loadConfig(buf); /* Lua to parse the configuration file */ conf_parseCLI( argc, argv ); /* parse CLI arguments */ /* Enable FPU exceptions. */ #if defined(HAVE_FEENABLEEXCEPT) && defined(DEBUGGING) if (conf.fpu_except) feenableexcept( FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW ); #endif /* defined(HAVE_FEENABLEEXCEPT) && defined(DEBUGGING) */ /* Open data. */ if (ndata_open() != 0) ERR("Failed to open ndata."); /* Load the start info. */ if (start_load()) ERR("Failed to load module start data."); /* Load the data basics. */ LOG(" %s", ndata_name()); DEBUG(); /* Display the SDL Version. */ print_SDLversion(); DEBUG(); /* random numbers */ rng_init(); /* * OpenGL */ if (gl_init()) { /* initializes video output */ ERR("Initializing video output failed, exiting..."); SDL_Quit(); exit(EXIT_FAILURE); } window_caption(); gl_fontInit( NULL, NULL, conf.font_size_def ); /* initializes default font to size */ gl_fontInit( &gl_smallFont, NULL, conf.font_size_small ); /* small font */ /* Display the load screen. */ loadscreen_load(); loadscreen_render( 0., "Initializing subsystems..." ); time_ms = SDL_GetTicks(); /* * Input */ if ((conf.joystick_ind >= 0) || (conf.joystick_nam != NULL)) { if (joystick_init()) WARN("Error initializing joystick input"); if (conf.joystick_nam != NULL) { /* use the joystick name to find a joystick */ if (joystick_use(joystick_get(conf.joystick_nam))) { WARN("Failure to open any joystick, falling back to default keybinds"); input_setDefault(); } free(conf.joystick_nam); } else if (conf.joystick_ind >= 0) /* use a joystick id instead */ if (joystick_use(conf.joystick_ind)) { WARN("Failure to open any joystick, falling back to default keybinds"); input_setDefault(); } } /* * OpenAL - Sound */ if (conf.nosound) { LOG("Sound is disabled!"); sound_disabled = 1; music_disabled = 1; } if (sound_init()) WARN("Problem setting up sound!"); music_choose("load"); /* FPS stuff. */ fps_setPos( 15., (double)(gl_screen.h-15-gl_defFont.h) ); /* Misc graphics init */ if (nebu_init() != 0) { /* Initializes the nebula */ /* An error has happened */ ERR("Unable to initialize the Nebula subsystem!"); /* Weirdness will occur... */ } gui_init(); /* initializes the GUI graphics */ toolkit_init(); /* initializes the toolkit */ map_init(); /* initializes the map. */ cond_init(); /* Initialize conditional subsystem. */ cli_init(); /* Initialize console. */ /* Data loading */ load_all(); /* Generate the CSV. */ if (conf.devcsv) dev_csv(); /* Unload load screen. */ loadscreen_unload(); /* Start menu. */ menu_main(); /* Force a minimum delay with loading screen */ if ((SDL_GetTicks() - time_ms) < NAEV_INIT_DELAY) SDL_Delay( NAEV_INIT_DELAY - (SDL_GetTicks() - time_ms) ); fps_init(); /* initializes the time_ms */ #if HAS_UNIX /* Tell the player to migrate their configuration files out of ~/.naev */ /* TODO get rid of this cruft ASAP. */ if ((oldconfig) && (!conf.datapath)) { char path[PATH_MAX], *script, *home; uint32_t scriptsize; int ret; nsnprintf( path, PATH_MAX, "%s/naev-confupdate.sh", ndata_getDirname() ); home = SDL_getenv("HOME"); ret = dialogue_YesNo( "Warning", "Your configuration files are in a deprecated location and must be migrated:\n" " \er%s/.naev/\e0\n\n" "The update script can likely be found in your Naev data directory:\n" " \er%s\e0\n\n" "Would you like to run it automatically?", home, path ); /* Try to run the script. */ if (ret) { ret = -1; /* Running from ndata. */ if (ndata_getPath() != NULL) { script = ndata_read( "naev-confupdate.sh", &scriptsize ); if (script != NULL) ret = system(script); } /* Running from laid-out files or ndata_read failed. */ if ((nfile_fileExists(path)) && (ret == -1)) { script = nfile_readFile( (int*)&scriptsize, path ); if (script != NULL) ret = system(script); } /* We couldn't find the script. */ if (ret == -1) { dialogue_alert( "The update script was not found at:\n\er%s\e0\n\n" "Please locate and run it manually.", path ); } /* Restart, as the script succeeded. */ else if (!ret) { dialogue_msg( "Update Completed", "Configuration files were successfully migrated. Naev will now restart." ); execv(argv[0], argv); } else { /* I sincerely hope this else is never hit. */ dialogue_alert( "The update script encountered an error. Please exit Naev and move your config and save files manually:\n\n" "\er%s/%s\e0 =>\n \eD%s\e0\n\n" "\er%s/%s\e0 =>\n \eD%s\e0\n\n" "\er%s/%s\e0 =>\n \eD%snebula/\e0\n\n", home, ".naev/conf.lua", nfile_configPath(), home, ".naev/{saves,screenshots}/", nfile_dataPath(), home, ".naev/gen/*.png", nfile_cachePath() ); } } else {
int main(int argc, char *argv[]) { size_t num_edges; aligned_t * rets; vertex_t * edges; for (int i = 0; i < NUM_VERTICES; i++) { in_degrees[i] = 0; } /* Initialize SPR in SPMD mode */ qthread_f actions[2] = {incr_in_degree, NULL}; spr_init(SPR_SPMD, actions); here = spr_locale_id(); num_locales = spr_num_locales(); if (0 == here) { printf("Running with %d locales\n", num_locales); } rng_init(rng_state.state, time(NULL) * here); /* Create local portion of the graph */ indices[0] = 0; for (int i = 1; i < NUM_VERTICES + 1; i++) { indices[i] = indices[i-1] + random_vertex(); } for (int i = 0; i < NUM_VERTICES + 1; i++) { printf("[%03d] indices[%d]: %lu\n", here, i, indices[i]); } num_edges = indices[NUM_VERTICES]; edges = malloc(num_edges * sizeof(vertex_t)); for (int i = 0; i < num_edges; i++) { edges[i].lid = random_locale(); edges[i].vid = random_vertex(); } for (int i = 0; i < num_edges; i++) { printf("[%03d] edges[%d]: (%lu,%lu)\n", here, i, edges[i].lid, edges[i].vid); } /* TODO: barrier */ /* Fill in-degrees property map */ rets = malloc(num_edges * sizeof(aligned_t)); for (int i = 0; i < NUM_VERTICES; i++) { for (int j = indices[i]; j < indices[i+1]; j++) { printf("[%03d] spawning incr of edge[%d] = (%lu,%lu)\n", here, j, edges[j].lid, edges[j].vid); qthread_fork_remote(incr_in_degree, /* action */ &(edges[j].vid), /* local vertex id */ &rets[j], /* feb */ edges[j].lid, /* locale */ sizeof(vertex_id_t)); } } for (int i = 0; i < num_edges; i++) { qthread_readFF(&rets[i], &rets[i]); } /* Print in-degrees */ for (int i = 0; i < NUM_VERTICES; i++) { printf("[%03d] in-degree(%lu) = %lu\n", here, i, in_degrees[i]); } /* Free up allocated resources */ free(rets); free(edges); return 0; }
uint32_t rng_get(void) { if (RNGHandle.State == HAL_RNG_STATE_RESET) { rng_init(); } return HAL_RNG_GetRandomNumber(&RNGHandle); }
void myinit(void) { #pragma message "myinit()" #pragma message "HAL_Init()" #pragma message "SystemClock_Config()" HAL_Init(); SystemClock_Config(); #ifdef ENABLE_GPIO #pragma message "led_init()" led_init(); #ifdef btn_init #pragma message "btn_init()" btn_init(); #endif #endif #ifdef ENABLE_RNG #pragma message "rng_init()" rng_init(); #endif #ifdef ENABLE_UART #pragma message "uart_init()" uart_init(); #endif #ifdef ENABLE_I2C #pragma message "i2c_init()" i2c_init(); #endif #ifdef ENABLE_SPI #pragma message "spi_init()" spi_init(); #endif #ifdef ENABLE_TIM #pragma message "tim_init()" tim_init(); #endif #ifdef ENABLE_ADC #pragma message "adc_init()" adc_init(); #endif #ifdef ENABLE_CAN #pragma message "can_init()" can_init(); #endif #ifdef ENABLE_DAC #pragma message "dac_init()" dac_init(); #endif #ifdef ENABLE_DMA #pragma message "dma_init()" dma_init(); #endif #ifdef ENABLE_FLASH #pragma message "flash_erase_img1()" flash_erase_img1(); #endif #ifdef ENABLE_ETH #pragma message "eth_init()" eth_init(); #endif #ifdef ENABLE_DSP #pragma message "dsp_init()" dsp_init(); #endif #ifdef ENABLE_USB #pragma message "usb_init()" usb_init(); #endif #ifdef ENABLE_PCL #pragma message "pcl_init()" pcl_init(); #endif #ifdef ENABLE_SDIO #pragma message "sdio_init()" sdio_init(); #endif #ifdef ENABLE_DISPLAY #pragma message "display_init()" display_init(); #endif #ifdef ENABLE_BR #pragma message "br_init()" br_init(); #endif }
// -- wrapper function for rng_init(j) where j is only (!) a 31 or 63 bit // -- signed integer. CAMLprim value wrap_rng_init(value j) { CAMLparam1(j); rng_init((Ullong)Long_val(j)); // -- j is 31 or 63 bit signed integer CAMLreturn(Val_unit); }