int main(int argc, char* argv[]) { // Init the randomizer init_srand(); // Define all needed blocks uint8** block_f; uint8** block_fp; uint8*** block_o; uint8** block_c; uint8* whole_block; // Set the foc Blocks directly with the new recursive methods create_array int l_whole_block[] = {MAX_MEM}; CREATE_ARRAY create_array((uint8*)&whole_block, l_whole_block, 1); // Test, if malloc was successful if (MALLOC_FAIL || (whole_block == NULL)) { FREE_MALLOC if (whole_block != NULL) free_array(whole_block, l_whole_block, 1); printf("Error: Not possible to allocate Memory!\nTerminating program!\n"); return -1; }
co_rc_t co_daemon_create(co_start_parameters_t *start_parameters, co_daemon_t **co_daemon_out) { co_rc_t rc; co_daemon_t *daemon; init_srand(); daemon = (co_daemon_t *)co_os_malloc(sizeof(co_daemon_t)); if (daemon == NULL) { rc = CO_RC(OUT_OF_MEMORY); goto out; } memset(daemon, 0, sizeof(*daemon)); daemon->start_parameters = start_parameters; memcpy(daemon->config.config_path, start_parameters->config_path, sizeof(start_parameters->config_path)); rc = co_load_config_file(daemon); if (!CO_OK(rc)) { co_debug("error loading configuration\n"); goto out_free; } *co_daemon_out = daemon; return rc; out_free: co_os_free(daemon); out: return rc; }
int main(int argc, char* argv[]) { // Test 1 Byte init_srand(); uint8* block; int length = 0x55; int dim = 1; int l[1] = {length}; create_array_generic((void*)&block, l, dim, sizeof(uint8)); define_random_1d_block(block, length); print_block_1B(block, length); print_block_2B(block, length); free_array_generic((void*)block, l, dim); // Test 2 Bytes uint16* block2B; int lenght2 = 0x24; int dim2 = 1; int l2[1] = {lenght2}; create_array_generic((void*)&block2B, l2, dim2, sizeof(uint16)); define_random_1d_block((uint8*)block2B, lenght2*2); print_block_2B((uint8*)block2B, lenght2*2); free_array_generic((void*)block2B, l2, dim2); return 0; }
//main code int main(void) { //init stuff //init the ht1632c LED matrix driver chip ht1632c_init(); //init the ADC init_ADC(); //init srand() with a somewhat random number from ADC9's low bits init_srand(); //init button stuff for input and pullup //and setup INT0 for button if you set DO_YOU_WANT_BUTTON_INT0 init_button(); //init timer1 for use in triggering an interrupt //on overflow, which updates the display and calculates new generation. init_timer1(); //init the I/O for the 7 segment display control init_digit_pins(); init_segment_pins(); //reset the display with a "random" array using rand() reset_grid(); //test glider //fb[29] = 0b00100000; //fb[30] = 0b00101000; //fb[31] = 0b00110000; //variable to store generation_count for display on 7 segment displays uint16_t g_count=0; //enable global interrupts sei(); //infinite loop while(1){ //check if the update generation count flag has been set //by within the timer1 overflow interrupt. //if set put the updated value into g_count and reset the flag. if(update_gen_flag){ g_count = generation_count; update_gen_flag=0; } write_number(g_count); //write the g_count to 7 segment displays //write_number(generation_count); //if the seven_seg_error flag is set (output is over 999 for 3 digits) //then reset the grid if(seven_seg_error_flag){ reset_grid(); } } }
co_rc_t co_daemon_create(co_start_parameters_t *start_parameters, co_daemon_t **co_daemon_out) { co_rc_t rc; co_daemon_t *daemon; init_srand(); daemon = (co_daemon_t *)co_os_malloc(sizeof(co_daemon_t)); if (daemon == NULL) { rc = CO_RC(ERROR); goto out; } memset(daemon, 0, sizeof(*daemon)); co_list_init(&daemon->connected_modules); co_queue_init(&daemon->up_queue); daemon->start_parameters = start_parameters; memcpy(daemon->config.config_path, start_parameters->config_path, sizeof(start_parameters->config_path)); rc = co_console_create(80, 25, 25, &daemon->console); if (!CO_OK(rc)) goto out_free; rc = co_load_config_file(daemon); if (!CO_OK(rc)) { co_debug("error loading configuration\n"); goto out_free_console; } *co_daemon_out = daemon; return rc; out_free_console: co_console_destroy(daemon->console); out_free: co_os_free(daemon); out: return rc; }
#if defined(__FreeBSD__) || defined(__OpenBSD__) #include <sys/types.h> #include <unistd.h> #endif // defined(__FreeBSD__) || defined(__OpenBSD__) #ifdef _WIN32 #include <windows.h> int getpid() { return static_cast<int>(GetCurrentProcessId()); } #endif // _WIN32 int init_srand() { srand(static_cast<unsigned int>(getpid())); return 0; } static int init_srand_var = init_srand(); namespace CS { int random_int(int min, int max) { return static_cast<int>( static_cast<long long>(min) + static_cast<long long>(rand()) * static_cast<long long>(max - min) / static_cast<long long>(RAND_MAX)); } double random_double(double min, double max) { return min + (max - min) * (static_cast<double>(rand()) / static_cast<double>(RAND_MAX)); } } // namespace CS
void init( dcp_info_t * info, unsigned long alloc_size ) { int wsize; MPI_Comm_size(MPI_COMM_WORLD, &wsize); MPI_Comm_rank(MPI_COMM_WORLD, &grank); dictionary* ini; if (access("config.fti", R_OK) == 0) { ini = iniparser_load("config.fti"); if (ini == NULL) { WARN_MSG("failed to parse FTI config file!"); exit(EXIT_FAILURE); } } else { EXIT_STD_ERR("cannot access FTI config file!"); } finalTag = (int)iniparser_getint(ini, "Advanced:final_tag", 3107); numHeads = (int)iniparser_getint(ini, "Basic:head", 0); int nodeSize = (int)iniparser_getint(ini, "Basic:node_size", -1); headRank = grank - grank%nodeSize; char* env = getenv( "TEST_MODE" ); if( env ) { if( strcmp( env, "ICP" ) == 0 ) { info->test_mode = TEST_ICP; INFO_MSG("TEST MODE -> ICP"); } else if ( strcmp( env, "NOICP") == 0 ) { info->test_mode = TEST_NOICP; INFO_MSG("TEST MODE -> NOICP"); } else { info->test_mode = TEST_NOICP; INFO_MSG("TEST MODE -> NOICP"); } } else { info->test_mode = TEST_NOICP; INFO_MSG("TEST MODE -> NOICP"); } //DBG_MSG("alloc_size: %lu",0,alloc_size); init_share(); // init pattern pat = (uint32_t) rand(); // protect pattern and xor_info FTI_InitType( &FTI_UI, UI_UNIT ); FTI_Protect( PAT_ID, &pat, 1, FTI_UI ); FTI_InitType( &FTI_XOR_INFO, sizeof(xor_info_t) ); FTI_Protect( XOR_INFO_ID, info->xor_info, NUM_DCKPT, FTI_XOR_INFO ); FTI_Protect( NBUFFER_ID, &info->nbuffer, 1, FTI_INTG ); // check if alloc_size is sufficiant large if ( alloc_size < 101 ) EXIT_CFG_ERR("insufficiant allocation size"); // determine number of buffers usleep(5000*grank); srand(get_seed()); if ( FTI_Status() == 0 ) { info->nbuffer = rand()%10+1; } else { FTI_RecoverVar( NBUFFER_ID ); } // initialize structure info->buffer = (void**) malloc(info->nbuffer*sizeof(void*)); info->size = (unsigned long*) malloc(info->nbuffer*sizeof(unsigned long)); info->oldsize = (unsigned long*) malloc(info->nbuffer*sizeof(unsigned long)); info->hash = (unsigned char**) malloc(info->nbuffer*sizeof(unsigned char*)); int idx; for ( idx=0; idx<info->nbuffer; ++idx ) { info->buffer[idx] = NULL; info->hash[idx] = (unsigned char*) malloc(MD5_DIGEST_LENGTH); } allocate_buffers( info, alloc_size ); generate_data( info ); init_srand(); }