/* Build the set of hosts/VMs that have to be terminated. This function selects how_many VMs from the source set of * candidates. * Remark: In the paper by Malawski et al., no details are provided about how the VMs are selected in the source set. * Moreover, there is no check w.r.t. the size of the source set. * Assumptions: * 1) If the source set is too small, display a warning and return a smaller set than expected. * 2) Straightforward selection of the VMs in the set. Just pick the how_many first ones without any consideration of * the time remaining until the next hourly billing cycle. Just check if the VM is not currently executing a task */ xbt_dynar_t find_active_VMs_to_stop(int how_many, xbt_dynar_t source){ int i, found; long unsigned int source_size = xbt_dynar_length(source); xbt_dynar_t to_stop = xbt_dynar_new(sizeof(sg_host_t), NULL); sg_host_t v; if (how_many > source_size){ XBT_WARN("Trying to terminate more VMs than what is available (%d > %lu)." " Change the number of VMs to terminate to %lu", how_many, source_size, source_size); how_many = source_size; } i = 0; found = 0; while(found < how_many && i < xbt_dynar_length(source)){ /* No advanced selection process. Just pick the how_many first idle VMs in the source set. */ xbt_dynar_get_cpy(source, i, &v); HostAttribute attr = sg_host_user(v); if (!attr->idle_busy){ xbt_dynar_push(to_stop, &v); found++; } i++; } if (found < how_many) XBT_WARN("Trying to terminate too many VMs, some are busy... Change the number of VMs to terminate to %d", found); return to_stop; }
void smpi_shared_free(void *ptr) { char loc[PTR_STRLEN]; shared_metadata_t* meta; shared_data_t* data; if (!allocs) { XBT_WARN("Cannot free: nothing was allocated"); return; } if(!allocs_metadata) { XBT_WARN("Cannot free: no metadata was allocated"); } snprintf(loc, PTR_STRLEN, "%p", ptr); meta = (shared_metadata_t*)xbt_dict_get_or_null(allocs_metadata, loc); if (!meta) { XBT_WARN("Cannot free: %p was not shared-allocated by SMPI", ptr); return; } data = meta->data; if(!data) { XBT_WARN("Cannot free: something is broken in the metadata link"); return; } if(munmap(ptr, meta->size) < 0) { XBT_WARN("Unmapping of fd %d failed: %s", data->fd, strerror(errno)); } data->count--; if (data->count <= 0) { close(data->fd); xbt_dict_remove(allocs, data->loc); free(data->loc); } }
/** * This function is called by SIMIX_global_init() to initialize the context module. */ void SIMIX_context_mod_init() { xbt_assert(simix_global->context_factory == nullptr); #if HAVE_SMPI && (defined(__APPLE__) || defined(__NetBSD__)) std::string priv = simgrid::config::get_value<std::string>("smpi/privatization"); if (context_factory_name == "thread" && (priv == "dlopen" || priv == "yes" || priv == "default" || priv == "1")) { XBT_WARN("dlopen+thread broken on Apple and BSD. Switching to raw contexts."); context_factory_name = "raw"; } #endif #if HAVE_SMPI && defined(__FreeBSD__) if (context_factory_name == "thread" && simgrid::config::get_value<std::string>("smpi/privatization") != "no") { XBT_WARN("mmap broken on FreeBSD, but dlopen+thread broken too. Switching to dlopen+raw contexts."); context_factory_name = "raw"; } #endif /* select the context factory to use to create the contexts */ if (simgrid::kernel::context::factory_initializer != nullptr) { // Give Java a chance to hijack the factory mechanism simix_global->context_factory = simgrid::kernel::context::factory_initializer(); return; } /* use the factory specified by --cfg=contexts/factory:value */ for (auto const& factory : context_factories) if (context_factory_name == factory.first) { simix_global->context_factory = factory.second(); break; } if (simix_global->context_factory == nullptr) { XBT_ERROR("Invalid context factory specified. Valid factories on this machine:"); #if HAVE_RAW_CONTEXTS XBT_ERROR(" raw: high performance context factory implemented specifically for SimGrid"); #else XBT_ERROR(" (raw contexts were disabled at compilation time on this machine -- check configure logs for details)"); #endif #if HAVE_UCONTEXT_CONTEXTS XBT_ERROR(" ucontext: classical system V contexts (implemented with makecontext, swapcontext and friends)"); #else XBT_ERROR(" (ucontext was disabled at compilation time on this machine -- check configure logs for details)"); #endif #if HAVE_BOOST_CONTEXTS XBT_ERROR(" boost: this uses the boost libraries context implementation"); #else XBT_ERROR(" (boost was disabled at compilation time on this machine -- check configure logs for details. Did you install the libboost-context-dev package?)"); #endif XBT_ERROR(" thread: slow portability layer using pthreads as provided by gcc"); xbt_die("Please use a valid factory."); } }
// Allgather-Non-Topoloty-Scecific-Logical-Ring algorithm int smpi_coll_tuned_allgather_NTSLR_NB(void *sbuf, int scount, MPI_Datatype stype, void *rbuf, int rcount, MPI_Datatype rtype, MPI_Comm comm) { MPI_Aint rextent, sextent; MPI_Status status, status2; int i, to, from, rank, size; int send_offset, recv_offset; int tag = COLL_TAG_ALLGATHER; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); rextent = smpi_datatype_get_extent(rtype); sextent = smpi_datatype_get_extent(stype); MPI_Request *rrequest_array; MPI_Request *srequest_array; rrequest_array = (MPI_Request *) xbt_malloc(size * sizeof(MPI_Request)); srequest_array = (MPI_Request *) xbt_malloc(size * sizeof(MPI_Request)); // irregular case use default MPI fucntions if (scount * sextent != rcount * rextent) { XBT_WARN("MPI_allgather_NTSLR_NB use default MPI_allgather."); smpi_mpi_allgather(sbuf, scount, stype, rbuf, rcount, rtype, comm); return MPI_SUCCESS; } // topo non-specific to = (rank + 1) % size; from = (rank + size - 1) % size; //copy a single segment from sbuf to rbuf send_offset = rank * scount * sextent; smpi_mpi_sendrecv(sbuf, scount, stype, rank, tag, (char *)rbuf + send_offset, rcount, rtype, rank, tag, comm, &status); //start sending logical ring message int increment = scount * sextent; //post all irecv first for (i = 0; i < size - 1; i++) { recv_offset = ((rank - i - 1 + size) % size) * increment; rrequest_array[i] = smpi_mpi_irecv((char *)rbuf + recv_offset, rcount, rtype, from, tag + i, comm); } for (i = 0; i < size - 1; i++) { send_offset = ((rank - i + size) % size) * increment; srequest_array[i] = smpi_mpi_isend((char *)rbuf + send_offset, scount, stype, to, tag + i, comm); smpi_mpi_wait(&rrequest_array[i], &status); smpi_mpi_wait(&srequest_array[i], &status2); } free(rrequest_array); free(srequest_array); return MPI_SUCCESS; }
/* Note: field `unit' for the last element of parameter `units' should be nullptr. */ static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units, const char *entity_kind, const char *name, const char *error_msg, const char *default_unit) { char* ptr; double res; int i; errno = 0; res = strtod(string, &ptr); if (errno == ERANGE) surf_parse_error("value out of range: %s", string); if (ptr == string) surf_parse_error("cannot parse number: %s", string); if (ptr[0] == '\0') { if (res == 0) return res; // Ok, 0 can be unit-less XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg); ptr = (char*)default_unit; } for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++) { } if (units[i].unit != nullptr) res *= units[i].scale; else surf_parse_error("unknown unit: %s", ptr); return res; }
void gras_process_init() { char **env_iter; _gras_procdata = xbt_new0(gras_procdata_t, 1); gras_procdata_init(); /* initialize the host & process properties */ _host_properties = xbt_dict_new(); _process_properties = xbt_dict_new(); env_iter = environ; while (*env_iter) { char *equal, *buf = xbt_strdup(*env_iter); equal = strchr(buf, '='); if (!equal) { XBT_WARN ("The environment contains an entry without '=' char: %s (ignore it)", *env_iter); continue; } *equal = '\0'; xbt_dict_set(_process_properties, buf, xbt_strdup(equal + 1), xbt_free_f); free(buf); env_iter++; } }
void ETag_surfxml_link(){ simgrid::kernel::routing::LinkCreationArgs link; link.properties = current_property_set; current_property_set = nullptr; link.id = std::string(A_surfxml_link_id); link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str()); link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr; link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str()); link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr; link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr; switch (A_surfxml_link_sharing___policy) { case A_surfxml_link_sharing___policy_SHARED: link.policy = simgrid::s4u::Link::SharingPolicy::SHARED; break; case A_surfxml_link_sharing___policy_FATPIPE: link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE; break; case A_surfxml_link_sharing___policy_FULLDUPLEX: XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead."); link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; break; case A_surfxml_link_sharing___policy_SPLITDUPLEX: link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; break; default: surf_parse_error(std::string("Invalid sharing policy in link ") + link.id); break; } sg_platf_new_link(&link); }
inline static int smpi_main_wrapper(int argc, char **argv){ int ret = smpi_simulated_main_(argc,argv); if(ret !=0){ XBT_WARN("SMPI process did not return 0. Return value : %d", ret); smpi_process_data()->return_value=ret; } return 0; }
void surf_parse_warn(const char *fmt, ...) { va_list va; va_start(va,fmt); char *msg = bvprintf(fmt,va); va_end(va); XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg); free(msg); }
/* This deprecated function has to be called once the number of channel is fixed. I can't figure out a reason why anyone would like to call this function but nevermind. * \return the number of channel in the simulation. */ int MSG_get_channel_number(void) { XBT_WARN("DEPRECATED! Please use aliases instead"); xbt_assert((msg_global) && (msg_global->max_channel != 0), "Channel number not set yet!"); return msg_global->max_channel; }
/** * \brief Sets the rate of a task * * This will change the network bandwidth a task can use. This rate cannot be dynamically changed. Once the task has * started, this call is ineffective. This rate depends on both the nominal bandwidth on the route onto which the task * is scheduled (\see SD_task_get_current_bandwidth) and the amount of data to transfer. * * To divide the nominal bandwidth by 2, the rate then has to be : * rate = bandwidth/(2*amount) * * \param task a \see SD_TASK_COMM_E2E task (end-to-end communication) * \param rate the new rate you want to associate with this task. */ void SD_task_set_rate(SD_task_t task, double rate) { xbt_assert(task->kind == SD_TASK_COMM_E2E, "The rate can be modified for end-to-end communications only."); if(task->state < SD_RUNNING) { task->rate = rate; } else { XBT_WARN("Task %p has started. Changing rate is ineffective.", task); } }
static void dolog(const char *settings) { XBT_INFO("Test with the settings '%s'", settings); xbt_log_control_set(settings); XBT_DEBUG("val=%d", 1); XBT_WARN("val=%d", 2); XBT_CDEBUG(top, "val=%d%s", 3, "!"); XBT_CRITICAL("false alarm%s%s%s%s%s%s", "", "", "", "", "", "!"); }
int find_method(int list_methods_len,chor_method_data list_methods[],char task_name[]){ int i; for(i=0;i<list_methods_len;i++){ if(strcmp(task_name,list_methods[i].method) == 0) return i; } XBT_WARN("method %s not found",task_name); return -1; }
void smpi_shared_free(void *ptr) { shared_data_t *data = (shared_data_t *) ((int *) ptr - 1); char *loc; if (!allocs) { XBT_WARN("Cannot free: nothing was allocated"); return; } loc = xbt_dict_get_key(allocs, data); if (!loc) { XBT_WARN("Cannot free: %p was not shared-allocated by SMPI", ptr); return; } data->count--; if (data->count <= 0) { xbt_dict_remove(allocs, loc); } }
/** \ingroup msg_mailbox_management * \brief Get a task from a mailbox on a given host at a given rate * * \param mailbox The mailbox where the task was sent * \param task a memory location for storing a #msg_task_t. * \param host a #msg_host_t host from where the task was sent * \param timeout a timeout * \param rate a rate * \return Returns * #MSG_OK if the task was successfully received, * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise. */ msg_error_t MSG_mailbox_get_task_ext_bounded(msg_mailbox_t mailbox, msg_task_t * task, msg_host_t host, double timeout, double rate) { xbt_ex_t e; msg_error_t ret = MSG_OK; /* We no longer support getting a task from a specific host */ if (host) THROW_UNIMPLEMENTED; TRACE_msg_task_get_start(); double start_time = MSG_get_clock(); /* Sanity check */ xbt_assert(task, "Null pointer for the task storage"); if (*task) XBT_WARN ("Asked to write the received task in a non empty struct -- proceeding."); /* Try to receive it by calling SIMIX network layer */ TRY { simcall_comm_recv(mailbox, task, NULL, NULL, NULL, NULL, timeout, rate); XBT_DEBUG("Got task %s from %p",(*task)->name,mailbox); if (msg_global->debug_multiple_use && (*task)->simdata->isused!=0) xbt_ex_free(*(xbt_ex_t*)(*task)->simdata->isused); (*task)->simdata->isused = 0; } CATCH(e) { switch (e.category) { case cancel_error: ret = MSG_HOST_FAILURE; break; case network_error: ret = MSG_TRANSFER_FAILURE; break; case timeout_error: ret = MSG_TIMEOUT; break; case host_error: ret = MSG_HOST_FAILURE; break; default: RETHROW; } xbt_ex_free(e); } if (ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) { TRACE_msg_task_get_end(start_time, *task); } MSG_RETURN(ret); }
msg_mailbox_t MSG_mailbox_get_by_channel(msg_host_t host, m_channel_t channel) { XBT_WARN("DEPRECATED! Now use MSG_mailbox_get_by_alias"); xbt_assert((host != NULL), "Invalid host"); xbt_assert((channel >= 0) && (channel < msg_global->max_channel), "Invalid channel %d", channel); return host->mailboxes[(size_t) channel]; }
/* This deprecated function has to be called to fix the number of channel in the simulation before creating any host. Indeed, each channel is represented by a different mailbox on each #m_host_t. This function can then be called only once. This function takes only one parameter. * \param number the number of channel in the simulation. It has to be >0 */ msg_error_t MSG_set_channel_number(int number) { XBT_WARN("DEPRECATED! Please use aliases instead"); xbt_assert((msg_global) && (msg_global->max_channel == 0), "Channel number already set!"); msg_global->max_channel = number; return MSG_OK; }
/** \ingroup msg_file_management * \brief Write into a file (local or remote) * * \param size of the file to write * \param fd is a the file descriptor * \return the number of bytes successfully write or -1 if an error occurred */ sg_size_t MSG_file_write(msg_file_t fd, sg_size_t size) { msg_file_priv_t file_priv = MSG_file_priv(fd); sg_size_t write_size, offset; /* Find the host where the file is physically located (remote or local)*/ msg_storage_t storage_src =(msg_storage_t) xbt_lib_get_elm_or_null(storage_lib, file_priv->storageId); msg_storage_priv_t storage_priv_src = MSG_storage_priv(storage_src); msg_host_t attached_host = MSG_get_host_by_name(storage_priv_src->hostname); if(strcmp(storage_priv_src->hostname, MSG_host_get_name(MSG_host_self()))){ /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */ XBT_DEBUG("File is on %s remote host, initiate data transfer of %llu bytes.", storage_priv_src->hostname, size); msg_host_t *m_host_list = NULL; m_host_list = calloc(2, sizeof(msg_host_t)); m_host_list[0] = MSG_host_self(); m_host_list[1] = attached_host; double flops_amount[] = { 0, 0 }; double bytes_amount[] = { 0, (double)size, 0, 0 }; msg_task_t task = MSG_parallel_task_create("file transfer for write", 2, m_host_list, flops_amount, bytes_amount, NULL); msg_error_t transfer = MSG_parallel_task_execute(task); MSG_task_destroy(task); free(m_host_list); if(transfer != MSG_OK){ if (transfer == MSG_HOST_FAILURE) XBT_WARN("Transfer error, %s remote host just turned off!", MSG_host_get_name(attached_host)); if (transfer == MSG_TASK_CANCELED) XBT_WARN("Transfer error, task has been canceled!"); return -1; } } /* Write file on local or remote host */ offset = simcall_file_tell(file_priv->simdata->smx_file); write_size = simcall_file_write(file_priv->simdata->smx_file, size, attached_host); file_priv->size = offset+write_size; return write_size; }
static int dot_parse_int(const char *string) { if (string == NULL) return -10; int ret = 0; int value = -1; ret = sscanf(string, "%d", &value); if (ret != 1) XBT_WARN("%s is not an integer", string); return value; }
int Coll_bcast_flattree_pipeline::bcast(void *buff, int count, MPI_Datatype data_type, int root, MPI_Comm comm) { int i, j, rank, num_procs; int tag = COLL_TAG_BCAST; MPI_Aint extent; extent = data_type->get_extent(); int segment = flattree_segment_in_byte / extent; segment = segment == 0 ? 1 :segment; int pipe_length = count / segment; int increment = segment * extent; if (pipe_length==0) { XBT_WARN("MPI_bcast_flattree_pipeline use default MPI_bcast_flattree."); return Coll_bcast_flattree::bcast(buff, count, data_type, root, comm); } rank = comm->rank(); num_procs = comm->size(); MPI_Request *request_array; MPI_Status *status_array; request_array = (MPI_Request *) xbt_malloc(pipe_length * sizeof(MPI_Request)); status_array = (MPI_Status *) xbt_malloc(pipe_length * sizeof(MPI_Status)); if (rank != root) { for (i = 0; i < pipe_length; i++) { request_array[i] = Request::irecv((char *)buff + (i * increment), segment, data_type, root, tag, comm); } Request::waitall(pipe_length, request_array, status_array); } else { // Root sends data to all others for (j = 0; j < num_procs; j++) { if (j == rank) continue; else { for (i = 0; i < pipe_length; i++) { Request::send((char *)buff + (i * increment), segment, data_type, j, tag, comm); } } } } free(request_array); free(status_array); return MPI_SUCCESS; }
tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input, double periodicity) { tmgr_trace_t trace = NULL; int linecount = 0; s_tmgr_event_t event; tmgr_event_t last_event = NULL; xbt_dynar_t list; unsigned int cpt; char *val; if (trace_list) { trace = xbt_dict_get_or_null(trace_list, id); if (trace) { XBT_WARN("Ignoring redefinition of trace %s", id); return trace; } } xbt_assert(periodicity >= 0, "Invalid periodicity %lg (must be positive)", periodicity); trace = xbt_new0(s_tmgr_trace_t, 1); trace->type = e_trace_list; trace->s_list.event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL); list = xbt_str_split(input, "\n\r"); xbt_dynar_foreach(list, cpt, val) { linecount++; xbt_str_trim(val, " \t\n\r\x0B"); if (val[0] == '#' || val[0] == '\0' || val[0] == '%') continue; if (sscanf(val, "PERIODICITY " "%lg" "\n", &periodicity) == 1) continue; if (sscanf(val, "%lg" " " "%lg" "\n", &event.delta, &event.value) != 2) xbt_die("%s:%d: Syntax error in trace\n%s", id, linecount, input); if (last_event) { if (last_event->delta > event.delta) { xbt_die("%s:%d: Invalid trace: Events must be sorted, " "but time %lg > time %lg.\n%s", id, linecount, last_event->delta, event.delta, input); } last_event->delta = event.delta - last_event->delta; } xbt_dynar_push(trace->s_list.event_list, &event); last_event = xbt_dynar_get_ptr(trace->s_list.event_list, xbt_dynar_length(trace->s_list.event_list) - 1); }
/* * \brief Frees private data of a host (internal call only) */ void __MSG_host_priv_free(msg_host_priv_t priv) { if (priv == NULL) return; unsigned int size = xbt_dict_size(priv->dp_objs); if (size > 0) XBT_WARN("dp_objs: %u pending task?", size); xbt_dict_free(&priv->dp_objs); xbt_dict_free(&priv->affinity_mask_db); xbt_dynar_free(&priv->file_descriptor_table); free(priv); }
void Session::logState() { mc_model_checker->getChecker()->logState(); if ((_sg_mc_dot_output_file != nullptr) && (_sg_mc_dot_output_file[0] != '\0')) { fprintf(dot_output, "}\n"); fclose(dot_output); } if (getenv("SIMGRID_MC_SYSTEM_STATISTICS")){ int ret=system("free"); if(ret!=0)XBT_WARN("system call did not return 0, but %d",ret); } }
/** \ingroup msg_trace_driven * \brief A trace loader * * If path!=NULL, load a trace file containing actions, and execute them. * Else, assume that each process gets the path in its deployment file */ msg_error_t MSG_action_trace_run(char *path) { msg_error_t res; char *name; xbt_dynar_t todo; xbt_dict_cursor_t cursor; xbt_action_fp=NULL; if (path) { xbt_action_fp = fopen(path, "r"); if (xbt_action_fp == NULL) xbt_die("Cannot open %s: %s", path, strerror(errno)); } res = MSG_main(); if (!xbt_dict_is_empty(xbt_action_queues)) { XBT_WARN ("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file."); xbt_dict_foreach(xbt_action_queues, cursor, name, todo) { XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name); }
/* * \brief Frees private data of a host (internal call only) */ void __MSG_host_priv_free(msg_host_priv_t priv) { unsigned int size = xbt_dict_size(priv->dp_objs); if (size > 0) XBT_WARN("dp_objs: %u pending task?", size); xbt_dict_free(&priv->dp_objs); xbt_dict_free(&priv->affinity_mask_db); #ifdef MSG_USE_DEPRECATED free(priv->mailboxes); #endif free(priv); }
int server(int argc, char *argv[]) { server_data_t *globals; int port = 4000; /* 1. Init the GRAS infrastructure and declare my globals */ gras_init(&argc, argv); globals = gras_userdata_new(server_data_t); /* 2. Get the port I should listen on from the command line, if specified */ if (argc == 2) { port = atoi(argv[1]); } XBT_INFO("Launch server (port=%d)", port); /* 3. Create my master socket */ globals->sock = gras_socket_server(port); /* 4. Register the known messages. This function is called twice here, but it's because this file also acts as regression test, no need to do so yourself of course. */ ping_register_messages(); ping_register_messages(); /* just to make sure it works ;) */ /* 5. Register my callback */ gras_cb_register("ping", &server_cb_ping_handler); XBT_INFO(">>>>>>>> Listening on port %d <<<<<<<<", gras_socket_my_port(globals->sock)); globals->endcondition = 0; /* 6. Wait up to 20 minutes for an incomming message to handle */ gras_msg_handle(20.0); /* 7. Housekeeping */ if (!globals->endcondition) XBT_WARN ("An error occured, the endcondition was not set by the callback"); /* 8. Free the allocated resources, and shut GRAS down */ gras_socket_close(globals->sock); free(globals); XBT_INFO("Done."); gras_exit(); return 0; } /* end_of_server */
int service_cordel(int argc,char *argv[]){ chor_method_data list_methods[12]; int list_methods_len = 0; char mailbox[50]; strcpy(mailbox,argv[1]); XBT_INFO("created service %s",mailbox); int count_arg = 2; while(count_arg < argc){ //add method if(strcmp(argv[count_arg],"method") == 0){ count_arg++; make_chor_method(&list_methods[list_methods_len],argv[count_arg],argv[count_arg+1],argv[count_arg+2]); XBT_INFO("method: %s",argv[count_arg]); count_arg = count_arg+3; //add instructions int number_of_instruction = 0; while(strcmp(argv[count_arg],"method") != 0){ if(strcmp(argv[count_arg],"invoke") == 0){ make_instruction(&list_methods[list_methods_len].instructions[number_of_instruction],INVOKE,argv[count_arg+1],argv[count_arg+2],atof(argv[count_arg+3])); count_arg = count_arg+4; }else if(strcmp(argv[count_arg],"invoke_a") == 0){ make_instruction(&list_methods[list_methods_len].instructions[number_of_instruction],INVOKE_A,argv[count_arg+1],argv[count_arg+2],atof(argv[count_arg+3])); count_arg = count_arg+4; }else if(strcmp(argv[count_arg],"exec") == 0){ list_methods[list_methods_len].instructions[number_of_instruction].type = EXEC; count_arg++; }else if(strcmp(argv[count_arg],"wait") == 0){ list_methods[list_methods_len].instructions[number_of_instruction].type = WAIT; count_arg++; }else if(strcmp(argv[count_arg],"return") == 0){ list_methods[list_methods_len].instructions[number_of_instruction].type = RETURN; count_arg++; }else{ XBT_WARN("parser arguments error"); return 1;} number_of_instruction++; if(count_arg >= argc){ break; } } list_methods[list_methods_len].instructions_len = number_of_instruction; list_methods_len++; } } run_service_cordel(list_methods_len,list_methods,mailbox); }
// Allgather-Non-Topoloty-Scecific-Logical-Ring algorithm int smpi_coll_tuned_allgather_NTSLR(void *sbuf, int scount, MPI_Datatype stype, void *rbuf, int rcount, MPI_Datatype rtype, MPI_Comm comm) { MPI_Aint rextent, sextent; MPI_Status status; int i, to, from, rank, size; int send_offset, recv_offset; int tag = COLL_TAG_ALLGATHER; rank = smpi_comm_rank(comm); size = smpi_comm_size(comm); rextent = smpi_datatype_get_extent(rtype); sextent = smpi_datatype_get_extent(stype); // irregular case use default MPI fucntions if (scount * sextent != rcount * rextent) { XBT_WARN("MPI_allgather_NTSLR use default MPI_allgather."); smpi_mpi_allgather(sbuf, scount, stype, rbuf, rcount, rtype, comm); return MPI_SUCCESS; } // topo non-specific to = (rank + 1) % size; from = (rank + size - 1) % size; //copy a single segment from sbuf to rbuf send_offset = rank * scount * sextent; smpi_mpi_sendrecv(sbuf, scount, stype, rank, tag, (char *)rbuf + send_offset, rcount, rtype, rank, tag, comm, &status); //start sending logical ring message int increment = scount * sextent; for (i = 0; i < size - 1; i++) { send_offset = ((rank - i + size) % size) * increment; recv_offset = ((rank - i - 1 + size) % size) * increment; smpi_mpi_sendrecv((char *) rbuf + send_offset, scount, stype, to, tag + i, (char *) rbuf + recv_offset, rcount, rtype, from, tag + i, comm, &status); } return MPI_SUCCESS; }
static double dot_parse_double(const char *string) { if (string == NULL) return -1; double value = -1; char *err; //ret = sscanf(string, "%lg", &value); errno = 0; value = strtod(string,&err); if(errno) { XBT_WARN("Failed to convert string to double: %s\n",strerror(errno)); return -1; } return value; }
void *smpi_shared_malloc(size_t size, const char *file, int line) { char *loc = bprintf("%zu_%s_%d", (size_t)getpid(), file, line); size_t len = strlen(loc); size_t i; int fd; void* mem; shared_data_t *data; for(i = 0; i < len; i++) { /* Make the 'loc' ID be a flat filename */ if(loc[i] == '/') { loc[i] = '_'; } } if (!allocs) { allocs = xbt_dict_new_homogeneous(free); } data = xbt_dict_get_or_null(allocs, loc); if(!data) { fd = shm_open(loc, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(fd < 0) { switch(errno) { case EEXIST: xbt_die("Please cleanup /dev/shm/%s", loc); default: xbt_die("An unhandled error occured while opening %s: %s", loc, strerror(errno)); } } data = xbt_new(shared_data_t, 1); data->fd = fd; data->count = 1; data->loc = loc; mem = shm_map(fd, size, data); if(shm_unlink(loc) < 0) { XBT_WARN("Could not early unlink %s: %s", loc, strerror(errno)); } xbt_dict_set(allocs, loc, data, NULL); XBT_DEBUG("Mapping %s at %p through %d", loc, mem, fd); } else { mem = shm_map(data->fd, size, data); data->count++; } XBT_DEBUG("Malloc %zu in %p (metadata at %p)", size, mem, data); return mem; }