void loadtopology_run(LoadTopologyAction* action) { MAGIC_ASSERT(action); Topology* topology = NULL; /* igraph wants a path to an graphml file, prefer a path over cdata */ if(action->path) { topology = topology_new(action->path->str); if(!topology) { error("error loading topology file '%s'", action->path->str); return; } } else { /* turn the cdata text contents into a file */ GString* templateBuffer = g_string_new("shadow-cdata-XXXXXX.graphml.xml"); /* try to open the templated file, checking for errors */ gchar* temporaryFilename = NULL; GError* error = NULL; gint openedFile = g_file_open_tmp(templateBuffer->str, &temporaryFilename, &error); if(openedFile < 0) { error("unable to open temporary file for cdata topology: %s", error->message); return; } /* cleanup */ close(openedFile); g_string_free(templateBuffer, TRUE); error = NULL; /* copy the cdata to the new temporary file */ if(!g_file_set_contents(temporaryFilename, action->text->str, (gssize)action->text->len, &error)) { error("unable to write cdata topology to '%s': %s", temporaryFilename, error->message); return; } topology = topology_new(temporaryFilename); g_unlink(temporaryFilename); g_free(temporaryFilename); if(!topology) { error("error loading topology cdata"); return; } } utility_assert(topology); worker_setTopology(topology); }
struct topology *infer_bus_topology( struct cfg_intern *def, struct inf_context *ctx) { (void) def; (void) ctx; struct topology *self = topology_new(); if(!self) return NULL; fprintf(stderr, "Bus topologies are not implemented yet\n"); abort(); return self; }
static gboolean _master_loadTopology(Master* master) { MAGIC_ASSERT(master); ConfigurationTopologyElement* e = configuration_getTopologyElement(master->config); gchar* temporaryFilename = utility_getNewTemporaryFilename("shadow-topology-XXXXXX.graphml.xml"); /* igraph wants a path to a graphml file, prefer a path over cdata */ if(e->path.isSet) { /* now make the configured path exist, pointing to the new file */ gint result = symlink(e->path.string->str, temporaryFilename); if(result < 0) { warning("Unable to create symlink at %s pointing to %s; symlink() returned %i error %i: %s", temporaryFilename, e->path.string->str, result, errno, g_strerror(errno)); } else { /* that better not be a dangling link */ g_assert(g_file_test(temporaryFilename, G_FILE_TEST_IS_SYMLINK) && g_file_test(temporaryFilename, G_FILE_TEST_IS_REGULAR)); message("new topology file '%s' now linked at '%s'", e->path.string->str, temporaryFilename); } } else { utility_assert(e->cdata.isSet); GError* error = NULL; /* copy the cdata to the new temporary filename */ if(!g_file_set_contents(temporaryFilename, e->cdata.string->str, (gssize)e->cdata.string->len, &error)) { error("unable to write cdata topology to '%s': %s", temporaryFilename, error->message); return FALSE; } } /* initialize global routing model */ master->topology = topology_new(temporaryFilename); g_unlink(temporaryFilename); if(!master->topology) { critical("fatal error loading topology at path '%s', check your syntax and try again", temporaryFilename); g_free(temporaryFilename); return FALSE; } g_free(temporaryFilename); /* initialize global DNS addressing */ master->dns = dns_new(); return TRUE; }
int hpx_init(int *argc, char ***argv) { int status = HPX_SUCCESS; // Start the internal clock libhpx_time_start(); here = malloc(sizeof(*here)); if (!here) { status = log_error("failed to allocate a locality.\n"); goto unwind0; } here->rank = -1; here->ranks = 0; here->epoch = 0; sigset_t set; sigemptyset(&set); dbg_check(pthread_sigmask(SIG_BLOCK, &set, &here->mask)); here->config = config_new(argc, argv); if (!here->config) { status = log_error("failed to create a configuration.\n"); goto unwind1; } // check to see if everyone is waiting if (config_dbg_waitat_isset(here->config, HPX_LOCALITY_ALL)) { dbg_wait(); } // bootstrap here->boot = boot_new(here->config->boot); if (!here->boot) { status = log_error("failed to bootstrap.\n"); goto unwind1; } here->rank = boot_rank(here->boot); here->ranks = boot_n_ranks(here->boot); // initialize the debugging system // @todo We would like to do this earlier but MPI_init() for the bootstrap // network overwrites our segv handler. if (LIBHPX_OK != dbg_init(here->config)) { goto unwind1; } // Now that we know our rank, we can be more specific about waiting. if (config_dbg_waitat_isset(here->config, here->rank)) { // Don't wait twice. if (!config_dbg_waitat_isset(here->config, HPX_LOCALITY_ALL)) { dbg_wait(); } } // see if we're supposed to output the configuration, only do this at rank 0 if (config_log_level_isset(here->config, HPX_LOG_CONFIG)) { if (here->rank == 0) { config_print(here->config, stdout); } } // topology discovery and initialization here->topology = topology_new(here->config); if (!here->topology) { status = log_error("failed to discover topology.\n"); goto unwind1; } // Initialize our instrumentation. if (inst_init(here->config)) { log_dflt("error detected while initializing instrumentation\n"); } // Allocate the global heap. here->gas = gas_new(here->config, here->boot); if (!here->gas) { status = log_error("failed to create the global address space.\n"); goto unwind1; } HPX_HERE = HPX_THERE(here->rank); here->percolation = percolation_new(); if (!here->percolation) { status = log_error("failed to activate percolation.\n"); goto unwind1; } int cores = system_get_available_cores(); dbg_assert(cores > 0); if (!here->config->threads) { here->config->threads = cores; } log_dflt("HPX running %d worker threads on %d cores\n", here->config->threads, cores); here->net = network_new(here->config, here->boot, here->gas); if (!here->net) { status = log_error("failed to create network.\n"); goto unwind1; } // thread scheduler here->sched = scheduler_new(here->config); if (!here->sched) { status = log_error("failed to create scheduler.\n"); goto unwind1; } #ifdef HAVE_APEX // initialize APEX, give this main thread a name apex_init("HPX WORKER THREAD"); apex_set_node_id(here->rank); #endif action_registration_finalize(); inst_start(); // start the scheduler, this will return after scheduler_shutdown() if (scheduler_startup(here->sched, here->config) != LIBHPX_OK) { log_error("scheduler shut down with error.\n"); goto unwind1; } if ((here->ranks > 1 && here->config->gas != HPX_GAS_AGAS) || !here->config->opt_smp) { status = hpx_run(&_hpx_143_fix); } return status; unwind1: _stop(here); _cleanup(here); unwind0: return status; }
struct topology *infer_bidi_topology( struct cfg_intern *def, struct inf_context *ctx) { struct cfg_m_str_a_str *layout; layout = inf_get_layout(ctx, def->layout); if(!layout) { return NULL; } struct topology *self = topology_new(); if(!self) return NULL; self->default_port = def->port; struct cfg_a_str *conn; for(conn = layout->val; conn; conn = conn->next) { char bindrole[25]; char connrole[25]; int source; if(sscanf(conn->val, "%24s -> %24s", bindrole, connrole) == 2) { source = 0; } else if(sscanf(conn->val, "%24s <- %24s", bindrole, connrole) == 2) { source = 1; } else { err_add_fatal(&ctx->err, "Bad layout rule \"%s\"\n", conn->val); continue; } struct role *bindr = roleht_get(&self->roles, bindrole); if(!bindr) { bindr = malloc(sizeof(struct role)); if(!bindr) goto memory_error; memcpy(bindr->name, bindrole, sizeof(bindrole)); rrules_init(&bindr->source_rules); rrules_init(&bindr->sink_rules); if(roleht_set(&self->roles, bindr->name, bindr) < 0) { free(bindr); goto memory_error; } } struct role *connr = roleht_get(&self->roles, connrole); if(!connr) { connr = malloc(sizeof(struct role)); if(!connr) goto memory_error; memcpy(connr->name, connrole, sizeof(connrole)); rrules_init(&connr->source_rules); rrules_init(&connr->sink_rules); if(roleht_set(&self->roles, connr->name, connr) < 0) { free(connr); goto memory_error; } } struct role_endpoint *ep1; struct role_endpoint *ep2; if(source == 0) { ep1 = rrules_add_endpoint(&bindr->source_rules, 0); ep2 = rrules_add_endpoint(&connr->sink_rules, 1); } else { ep1 = rrules_add_endpoint(&bindr->sink_rules, 0); ep2 = rrules_add_endpoint(&connr->source_rules, 1); } ep1->peer = ep2; ep2->peer = ep1; } struct cfg_m_str_a_str *roleip; for(roleip = def->ip_addresses; roleip; roleip = roleip->next) { struct role *role = roleht_get(&self->roles, roleip->key); if(!role) { err_add_fatal(&ctx->err, "Assignment for non-existent role \"%s\"\n", roleip->key); continue; } struct cfg_a_str *ip; for(ip = roleip->val; ip; ip = ip->next) { if(role_add_ip(role, ip->val) < 0) goto memory_error; } } /* TODO(tailhook) check that all endpoints to bind are assigned */ return self; memory_error: topology_free(self); return NULL; }