// --------------------------------------------------------------------------- /// Reads <b>run_mandor.cfg</b> file and sets all global static parameters (called from main()). // --------------------------------------------------------------------------- static void main_startUp (void) { // Loading time is a first estimate of a saving time. timeTick_t startUpStart; time_get (&startUpStart); main_allocateMeshes (); FILE *fp; int buffer[6]; if (!cpu_here) { fp = cfg_open ("run_mandor.cfg", "rt", __func__); // Reads checkpointing steps and startup flags. buffer[0] = cfg_readInt (fp); // - totalSteps. buffer[1] = cfg_readInt (fp); // - chPoint_full. buffer[2] = cfg_readInt (fp); // - chPoint_tecplot. buffer[3] = (1 == cfg_readInt (fp)); // - continueRun. buffer[4] = cfg_readInt (fp); // - chPoint_stopRequest buffer[5] = cfg_readInt (fp); // - chPoint_spectr fclose (fp); } // Broadcasts parameters. MPI_Bcast (buffer, 6, MPI_INT, 0, MPI_COMM_WORLD); totalSteps = buffer[0]; chPoint_full = buffer[1]; chPoint_tecplot = buffer[2]; int continueRun = buffer[3]; chPoint_stopRequest = buffer[4]; chPoint_spectr = buffer[5]; // Checks if sizes can be divided by. ENSURE (totalSteps*chPoint_full*chPoint_tecplot *chPoint_stopRequest*chPoint_spectr, "'run_mandor.cfg' contains zero step(s)"); // Sets time barrier. if (!(fp = fopen ("tmp/stop.flag", "rt"))) { fp = cfg_open ("tmp/stop.flag", "wt", __func__); // Sets timeout. SAY_DEBUG ("Setting timeout to 23h30m."); fprintf (fp, "0\n%d\n", 23*60*60 + 30*60); fclose (fp); } // Record are numbered as 0, .., N - 1. int point = sysIO_recordsTotal () - 1; MPI_Bcast (&point, 1, MPI_INT, 0, MPI_COMM_WORLD); // Chooses start-up mode. ENSURE (point >= 0, "initial checkpoint is not prepared"); if (continueRun && point != 0) { fileMap_init (mc_fileMap_contn); sysIO_setRecordNum (-1); // Continues check-pointing. tecIO_setRecordNum (-1); // Continues tecplot output. spectr_continueDump (); // Continues spectr output. } else { fileMap_init (mc_fileMap_start); sysIO_setRecordNum (1); // Starts to write just after setup record. tecIO_setRecordNum (1); // Starts to write just after setup record. spectr_startDump (); // Starts new spectr output sequence. point = 0; } // Initializes total energy diagnostic. wDensity_prepare (!(continueRun && point != 0)); /// \todo Partitioning options outside. SAY_WARNING("Explicit partitioning is blocked."); if (/*continueRun && point != 0 &&*/ 0) { partition_load ("output/partition_onStart.cfg"); // Loads old partitioning. } else { partition_init (); // Initializes partitioning. partition_save ("output/partition_onStart.cfg"); // Saves partitioning used. } // Sets the size of meshes using the partitioning. main_reconfigureMeshes (); double time; const reg_t to_load = {{cpu_min[0], cpu_min[1], cpu_min[2]}, {cpu_max[0], cpu_max[1], cpu_max[2]}, 0}; sysIO_loadEM (point, &time, &to_load, &E, &H); plasma_load (point); mf_mesh_clean (&J); mf_mesh_clean (&rho); parameter_setTime (time); parameter_dump (); // Prints parameters loaded. partition_show (); // Tecplot visualization of partititon. // Allocates probes and opens associated files. probe_allocate (continueRun && point > 0); say ("main_startUp: config file is imported. Parameters of the run are:"); say (" - %d total steps", totalSteps); say (" - %d steps between check-points", chPoint_full); if (chPoint_tecplot > 0) { say (" - %d steps between tecplot shots", chPoint_tecplot); } else { say (" - tecplot shots are off"); } if (chPoint_spectr > 0) { say (" - %d steps between spectral data dumps", chPoint_spectr); } else { say (" - EM spectral energy distribution diagnostic is off"); } say (" - %d steps between updating a stop request", chPoint_stopRequest); say (" - simulation is %s from check-point #%03d.", (continueRun && point != 0) ? "continued" : "started", point); // Loading time is a good estimate of saving time. timeTick_t startUpFinish; time_get (&startUpFinish); stopFlag_saveTime = time_elapsed (&startUpStart, &startUpFinish); // Configures convolutioner. double VSP_weight = 1.0; if (cl_findDouble ("VSP:weight", &VSP_weight)) VSP_weight = (VSP_weight > 0.5 && VSP_weight < 1.00001) ? VSP_weight : 1.00; VSP_configure (VSP_weight); }
/** * init module function */ static int mod_init(void) { LM_DBG("initializing ...\n"); if (check_if_default_head_is_ok()) { default_db_head.next = ds_db_heads; ds_db_heads = &default_db_head; } set_default_head_values(&default_db_head); ds_set_id_col.len = strlen(ds_set_id_col.s); ds_dest_uri_col.len = strlen(ds_dest_uri_col.s); ds_dest_sock_col.len = strlen(ds_dest_sock_col.s); ds_dest_state_col.len = strlen(ds_dest_state_col.s); ds_dest_weight_col.len = strlen(ds_dest_weight_col.s); ds_dest_attrs_col.len = strlen(ds_dest_attrs_col.s); if(hash_pvar_param.s && (hash_pvar_param.len=strlen(hash_pvar_param.s))>0){ if(pv_parse_format(&hash_pvar_param, &hash_param_model) < 0 || hash_param_model==NULL) { LM_ERR("malformed PV string: %s\n", hash_pvar_param.s); return -1; } } else { hash_param_model = NULL; } if(ds_setid_pvname.s && (ds_setid_pvname.len=strlen(ds_setid_pvname.s))>0){ if(pv_parse_spec(&ds_setid_pvname, &ds_setid_pv)==NULL || !pv_is_w(&ds_setid_pv)) { LM_ERR("[%s]- invalid setid_pvname\n", ds_setid_pvname.s); return -1; } } pvar_algo_param.len = strlen(pvar_algo_param.s); if (pvar_algo_param.len) ds_pvar_parse_pattern(pvar_algo_param); if (init_ds_bls()!=0) { LM_ERR("failed to init DS blacklists\n"); return E_CFG; } /* Creating partitions from head */ ds_db_head_t *head_it = ds_db_heads; while (head_it){ if (inherit_from_default_head(head_it) != 0) return -1; ds_partition_t *partition = shm_malloc (sizeof(ds_partition_t)); if (partition_init(head_it, partition) != 0) return -1; partition->next = partitions; partitions = partition; if (init_ds_data(partition)!=0) { LM_ERR("failed to init DS data holder\n"); return -1; } /* open DB connection to load provisioning data */ if (init_ds_db(partition)!= 0) { LM_ERR("failed to init database support\n"); return -1; } /* do the actual data load */ if (ds_reload_db(partition)!=0) { LM_ERR("failed to load data from DB\n"); return -1; } /* close DB connection */ ds_disconnect_db(partition); ds_db_head_t *aux = head_it; /* We keep track of corespondig default parition */ if (head_it == &default_db_head) default_partition = partition; head_it = head_it->next; if (aux != &default_db_head) pkg_free(aux); } /* Only, if the Probing-Timer is enabled the TM-API needs to be loaded: */ if (ds_ping_interval > 0) { load_tm_f load_tm; str host; int port,proto; if (ds_ping_from.s) ds_ping_from.len = strlen(ds_ping_from.s); if (ds_ping_method.s) ds_ping_method.len = strlen(ds_ping_method.s); /* parse the list of reply codes to be counted as success */ if(options_reply_codes_str.s) { options_reply_codes_str.len = strlen(options_reply_codes_str.s); if(parse_reply_codes(&options_reply_codes_str,&options_reply_codes, &options_codes_no )< 0) { LM_ERR("Bad format for options_reply_code parameter" " - Need a code list separated by commas\n"); return -1; } } /* parse and look for the socket to ping from */ if (probing_sock_s && probing_sock_s[0]!=0 ) { if (parse_phostport( probing_sock_s, strlen(probing_sock_s), &host.s, &host.len, &port, &proto)!=0 ) { LM_ERR("socket description <%s> is not valid\n", probing_sock_s); return -1; } probing_sock = grep_sock_info( &host, port, proto); if (probing_sock==NULL) { LM_ERR("socket <%s> is not local to opensips (we must listen " "on it\n", probing_sock_s); return -1; } } /* TM-Bindings */ load_tm=(load_tm_f)find_export("load_tm", 0, 0); if (load_tm==NULL) { LM_ERR("failed to bind to the TM-Module - required for probing\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb ) == -1) { LM_ERR("could not load the TM-functions - disable DS ping\n"); return -1; } /* Register the PING-Timer */ if (register_timer("ds-pinger", ds_check_timer, NULL, ds_ping_interval, TIMER_FLAG_DELAY_ON_DELAY)<0) { LM_ERR("failed to register timer for probing!\n"); return -1; } } /* register timer to flush the state of destination back to DB */ if (ds_persistent_state && register_timer("ds-flusher", ds_flusher_routine, NULL, 30 , TIMER_FLAG_SKIP_ON_DELAY)<0) { LM_ERR("failed to register timer for DB flushing!\n"); return -1; } dispatch_evi_id = evi_publish_event(dispatcher_event); if (dispatch_evi_id == EVI_ERROR) LM_ERR("cannot register dispatcher event\n"); return 0; }
// --------------------------------------------------------------------------- /// Entry point for \b phasedot diagnostic. // --------------------------------------------------------------------------- int main (int argc, char *argv[]) { parameter_enterMPI (argc, argv, 0, NULL); // Initializes log-file and MPI frame. const int lastCheckPoint = sysIO_recordsTotal () - 1; // Loads last record number. units_load (); // Loads all units. FILE *fp = cfg_open ("diag_phasedot.cfg", "rt", "tecplot.out"); // Reads parameters of the data processing. int start = cfg_readInt (fp); int end = cfg_readInt (fp); int step = cfg_readInt (fp); int writePLTFile = cfg_readInt (fp); ///< \todo Banish this dummy to hell. int unitsMicronFemtosec = cfg_readInt (fp) == 1; // Clamps to use as array index. double qDivM = cfg_readDouble (fp); // Gets desired q/M ratio. fclose (fp); if (end < 0 || end > lastCheckPoint) // Sets range of records (max or given). end = lastCheckPoint; if (start < 0 || start > end) error ("phasedot.cfg: bad start record number."); if (step <= 0) error ("phasedot.cfg: bad step."); double femtosecond = 1, micron = 1; // Chooses units. if (unitsMicronFemtosec) { femtosecond = units (mc_femtosecond); micron = units (mc_micron); } msg_setRefreshTime (0.2); say ("Start to generate phase-plane(dot) data file...\n"); fp = cfg_open ("output/phasedot.dat", "wt", "phasedot.out"); fprintf (fp, "variables = x, y, z, `gv_x, `gv_y, `gv_z, q\n"); for (int record = start ; record <= end ; record += step) { double time; int ID, revision; markerIterator_t page; sysIO_parameters (record, &revision, &time, NULL, NULL, NULL); // Loads DF. parameter_load (revision); partition_init (); reg_t reg; reg.min[0] = dmn.imin - 10; reg.min[1] = dmn.jmin - 10; reg.min[2] = dmn.kmin - 10; reg.max[0] = dmn.imax + 10; reg.max[1] = dmn.jmax + 10; reg.max[2] = dmn.kmax + 10; sysIO_loadPlasma (record, &time, ®); // filter_prepare (); filter_keep (qDivM); markerN = 0; // Finds the total number of particles. for (ID = markerChapter_first () ; ID >= 0 ; markerChapter_next (&ID)) for (markerPage_first (ID, &page) ; page.df ; markerPage_next (&page)) markerN += page.N; static const char titles[2][17] = {"t[t<sub>0</sub>]\0", "t[fs]\0"}; fprintf (fp, "zone t=\"%s=%.3f\", i = %d, f = point\n", titles[unitsMicronFemtosec], time/femtosecond, markerN); for (ID = markerChapter_first () ; ID >= 0 ; markerChapter_next (&ID)) for (markerPage_first (ID, &page) ; page.df ; markerPage_next (&page)) { marker_t *f = page.df; for (int p = 0 ; p < page.N ; p++) fprintf (fp, "%.4e %.4e %.4e %.4e %.4e %.4e %.4e\n", f[p].x/micron, f[p].y/micron, f[p].z/micron, f[p].vx, f[p].vy, f[p].vz, f[p].rho); } say_doing ("time = %.4f (%d particles)", time, markerN); } fclose (fp); return EXIT_SUCCESS; }
/** * Create an array of unbalanced partitions according to a distribution vector */ partition* greedyBFS_helper(list_graph* graph, int pnum, int* seeds){ //Allocate space for the data structures partition* parray = (partition *) malloc(sizeof(partition)*pnum); list* dest_list = (list *) malloc(sizeof(list)*pnum); list* src_list = (list *) malloc(sizeof(list)*pnum); int* src = (int*) malloc(sizeof(int)*pnum); int* dest = (int*) malloc(sizeof(int)*pnum); //Initialize the data structures and perform the initial discovery process int i, tmp; int maxtmp = -1; int maxi = -1; /** * Initialization */ for ( i = 0; i < pnum; i++){ //Mark seeds as partitioned graph->vertex[seeds[i]].color = 2; //Initialize and insert partition_init(&parray[i], graph->id, i); partition_add(&parray[i], seeds[i], 0); //Populate the lists with starting nodes and constraints list_init(&src_list[i]); list_init(&dest_list[i]); partition_constraint_add(&parray[i], &(graph->vertex[seeds[i]].constraints)); greedyBFS_discovery(graph, &dest_list[i], &parray[i], seeds[i]); //Find the best seed to start with tmp = greedyBFS_peek(graph, &parray[i], seeds[i]); if (tmp > maxtmp){ maxi = i; maxtmp = tmp; } //Set initial src and dst src[i] = seeds[i]; dest[i] = list_pop(&dest_list[i]); list_insert(&src_list[i], dest[i]); } /** * Partitioning */ while (maxtmp != -1){ printf("[%d]->[%d]:[%d]\n", src[maxi], dest[maxi], maxi); //Grow the partition list* l = greedyBFS_grow(graph, &parray[maxi], src[maxi], dest[maxi]); //Insert new data into the queue int pop = list_pop(l); while (pop != -1){ list_insert(&dest_list[maxi], pop); pop = list_pop(l); } //update src and dest if needed dest[maxi] = list_pop(&dest_list[maxi]); if (dest[maxi] >= 0) list_insert(&src_list[maxi], dest[maxi]); if (dest[maxi] != -1){ while(greedyBFS_peek(graph, &parray[maxi], src[maxi]) == -1){ src[maxi] = list_pop(&src_list[maxi]); if(src[maxi] == -1) break; } } //Find the new best partition and update src and dest if needed maxtmp = -1; for ( i = 0; i < pnum; i++){ if (src[i] == -1) tmp = -1; else tmp = greedyBFS_peek(graph, &parray[i], src[i]); if (tmp > maxtmp){ maxi = i; maxtmp = tmp; } } } /** * Fragments */ /*int alloc = graph->wgt; greedyBFS_grow(graph, &parray[i], *seeds++, alloc);*/ //greedyBFS_fragment_scan(graph, parray, pnum); /** * Cleanup */ return parray; }
void _main() { mem_extent_t *ramext; u8 sn[6]; u32 cpu_clk_hz = 0; rtc_time_t tm; s32 ret; /* This section runs with interrupts disabled. The boot console is not available in this section. */ preempt_disable(); /* Copy kernel read/write data areas into kernel RAM */ memcpy(&_sdata, &_etext, &_edata - &_sdata); /* Copy .data section to kernel RAM */ bzero(&_sbss, &_ebss - &_sbss); /* Initialise .bss section */ /* Begin platform initialisation */ if(plat_init() != SUCCESS) boot_early_fail(1); if(plat_mem_detect() != SUCCESS) /* Detect installed RAM, initialise memory extents */ boot_early_fail(2); /* Initialise kernel slabs */ slab_init(&_ebss); /* Slabs sit after the .bss section */ /* Initialise kernel heap */ kmeminit(g_slab_end, mem_get_highest_addr(MEM_EXTENT_KERN | MEM_EXTENT_RAM) - KERNEL_STACK_LEN); /* Initialise user heap. Place it in the largest user RAM extent. */ ramext = mem_get_largest_extent(MEM_EXTENT_USER | MEM_EXTENT_RAM); umeminit(ramext->base, ramext->base + ramext->len); /* By default, all exceptions cause a context-dump followed by a halt. */ cpu_irq_init_table(); /* Initialise device tree */ if(dev_init() != SUCCESS) boot_early_fail(3); /* It's not yet possible to initialise the real (platform) console because devices haven't been enumerated and interrupts are disabled. In the meantime, create a temporary in-memory kernel console device to capture output from the boot process. */ if(early_boot_console_init() != SUCCESS) boot_early_fail(4); printf("%s\nplatform: %s\n", g_warmup_message, plat_get_name()); printf("%uMB RAM detected\n", (mem_get_total_size(MEM_EXTENT_USER | MEM_EXTENT_RAM) + mem_get_total_size(MEM_EXTENT_KERN | MEM_EXTENT_RAM)) >> 20); /* === Initialise peripherals - phase 2 === */ if(dev_enumerate() != SUCCESS) boot_early_fail(5); /* Initialise the console */ if(plat_console_init() != SUCCESS) boot_early_fail(6); ret = sched_init("[sys]"); /* Init scheduler and create system process */ /* Enable interrupts and continue booting */ preempt_enable(); /* Copy the contents of the temporary console to the real console; close the temp console. */ early_boot_console_close(); /* Activate red LED while the boot process continues */ plat_led_off(LED_ALL); plat_led_on(LED_RED); /* Device enumeration is done; interrupts are enabled, and the console should be functional. Booting continues... */ /* Zero any user RAM extents. This happens after init'ing the DUART, because beeper. */ /* put("Clearing user RAM: "); mem_zero_extents(MEM_EXTENT_USER | MEM_EXTENT_RAM); puts("done"); */ /* Initialise the block cache, then scan mass-storage devices for partitions */ block_cache_init(2039); partition_init(); boot_list_mass_storage(); boot_list_partitions(); /* ret is set by the call to sched_init(), above */ if(ret != SUCCESS) printf("sched: init failed: %s\n", kstrerror(ret)); ret = vfs_init(); if(ret != SUCCESS) printf("vfs: init failed: %s\n", kstrerror(ret)); /* Display approximate CPU clock speed */ if(plat_get_cpu_clock(&cpu_clk_hz) == SUCCESS) printf("\nCPU fclk ~%2u.%uMHz\n", cpu_clk_hz / 1000000, (cpu_clk_hz % 1000000) / 100000); /* Initialise tick handler */ tick_init(); /* Display memory information */ printf("%u bytes of kernel heap memory available\n" "%u bytes of user memory available\n", kfreemem(), ufreemem()); /* Display platform serial number */ if(plat_get_serial_number(sn) == SUCCESS) { printf("Hardware serial number %02X%02X%02X%02X%02X%02X\n", sn[0], sn[1], sn[2], sn[3], sn[4], sn[5]); } /* Display the current date and time */ if(get_time(&tm) == SUCCESS) { char timebuf[12], datebuf[32]; if((time_iso8601(&tm, timebuf, sizeof(timebuf)) == SUCCESS) && (date_long(&tm, datebuf, sizeof(datebuf)) == SUCCESS)) printf("%s %s\n", timebuf, datebuf); else puts("Date/time invalid - please set clock"); } /* Create housekeeper process */ // proc_create(0, 0, "[hk]", NULL, housekeeper, 0, 0, PROC_TYPE_KERNEL, NULL, NULL); /* Initialise networking system */ ret = net_init(); if(ret != SUCCESS) printf("net: init failed: %s\n", kstrerror(ret)); /* Startup complete - activate green LED */ plat_led_off(LED_RED); plat_led_on(LED_GREEN); monitor(); /* start interactive "shell" thing */ cpu_halt(); /* should never be reached */ }
int main (int argc, char **argv) { const task_t my_task = mach_task_self(); error_t err; memory_object_t defpager; err = get_privileged_ports (&bootstrap_master_host_port, &bootstrap_master_device_port); if (err) error (1, err, "cannot get privileged ports"); defpager = MACH_PORT_NULL; err = vm_set_default_memory_manager (bootstrap_master_host_port, &defpager); if (err) error (1, err, "cannot check current default memory manager"); if (MACH_PORT_VALID (defpager)) error (2, 0, "Another default memory manager is already running"); if (!(argc == 2 && !strcmp (argv[1], "-d"))) { /* We don't use the `daemon' function because we might exit back to the parent before the daemon has completed vm_set_default_memory_manager. Instead, the parent waits for a SIGUSR1 from the child before exitting, and the child sends that signal after it is set up. */ sigset_t set; signal (SIGUSR1, nohandler); sigemptyset (&set); sigaddset (&set, SIGUSR1); sigprocmask (SIG_BLOCK, &set, 0); switch (fork ()) { case -1: error (1, errno, "cannot become daemon"); case 0: setsid (); chdir ("/"); close (0); close (1); close (2); break; default: sigemptyset (&set); sigsuspend (&set); _exit (0); } } /* Mark us as important. */ mach_port_t proc = getproc (); if (proc == MACH_PORT_NULL) error (3, err, "cannot get a handle to our process"); err = proc_mark_important (proc); /* This might fail due to permissions or because the old proc server is still running, ignore any such errors. */ if (err && err != EPERM && err != EMIG_BAD_ID) error (3, err, "cannot mark us as important"); mach_port_deallocate (mach_task_self (), proc); printf_init(bootstrap_master_device_port); /* * Set up the default pager. */ partition_init(); /* * task_set_exception_port and task_set_bootstrap_port * both require a send right. */ (void) mach_port_insert_right(my_task, default_pager_exception_port, default_pager_exception_port, MACH_MSG_TYPE_MAKE_SEND); /* * Change our exception port. */ if (!debug) (void) task_set_exception_port(my_task, default_pager_exception_port); default_pager_initialize (bootstrap_master_host_port); if (!(argc == 2 && !strcmp (argv[1], "-d"))) kill (getppid (), SIGUSR1); /* * Become the default pager */ default_pager(); /*NOTREACHED*/ return -1; }