static int process_code(int argc, char *argv[]) { msg_task_t task1 = NULL; double cpu_task = 0; double task_time = MSG_get_clock(); if (argc == 2) { /* Run a sleep task */ double sleep_task = atof(argv[1]); MSG_process_sleep(sleep_task); task_time = MSG_get_clock() - task_time; XBT_INFO("Process %s executed task sleep cpu=%f, duration = %f", MSG_process_get_name(MSG_process_self()), 0.0, task_time); XBT_INFO("=================================================="); } // Run a task cpu_task = atof(argv[0]); task1 = MSG_task_create ("task", cpu_task, 0, NULL); MSG_task_execute (task1); MSG_task_destroy(task1); task_time = MSG_get_clock() - task_time; XBT_INFO("Process %s executed task cpu=%f, duration = %f", MSG_process_get_name(MSG_process_self()), cpu_task, task_time); XBT_INFO("=================================================="); return 0; }
/** \ingroup msg_task_usage * \brief Sleep for the specified number of seconds * * Makes the current process sleep until \a time seconds have elapsed. * * \param nb_sec a number of second */ msg_error_t MSG_process_sleep(double nb_sec) { xbt_ex_t e; msg_error_t status = MSG_OK; /*msg_process_t proc = MSG_process_self();*/ TRACE_msg_process_sleep_in(MSG_process_self()); TRY { simcall_process_sleep(nb_sec); } CATCH(e) { switch (e.category) { case cancel_error: XBT_DEBUG("According to the JAVA API, a sleep call should only deal with HostFailureException, WTF here ?"); // adsein: MSG_TASK_CANCELED is assigned when someone kills the process that made the sleep, this is not // correct. For instance, when the node is turned off, the error should be MSG_HOST_FAILURE, which is by the way // and according to the JAVA document, the only exception that can be triggered by MSG_Process_sleep call. // To avoid possible impacts in the code, I just raised a host_failure exception for the moment in the JAVA code // and did not change anythings at the C level. // See comment in the jmsg_process.c file, function JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) status = MSG_TASK_CANCELED; break; default: RETHROW; } xbt_ex_free(e); } TRACE_msg_process_sleep_out(MSG_process_self()); MSG_RETURN(status); }
static void simopen(const char *const *action) { const char *processid = action[0]; const char *worktime = action[3]; double sleeptime; const char *index = action[4]; char full_name[1024]; msg_file_t file = NULL; double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */ //Because the action open is too fast ,to catch up with the clock of the simulator, we let it to sleep for a while. sleeptime = atof(worktime); MSG_process_sleep(sleeptime); //open slow filename const char *file_name = action[2]; char fn[200]; strcpy(fn,file_name); ReplaceStr(fn,"/home","/slow"); sprintf(full_name, "%s:%s:%s:%s","slow",file_name,MSG_process_get_name(MSG_process_self()),index); ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name); file = MSG_file_open(fn, NULL); xbt_dict_set(opened_files, full_name, file, NULL); //open fast filename strcpy(fn,file_name); ReplaceStr(fn,"/home","/fast"); sprintf(full_name, "%s:%s:%s:%s","fast",file_name,MSG_process_get_name(MSG_process_self()),index); ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name); file = MSG_file_open(fn, NULL); xbt_dict_set(opened_files, full_name, file, NULL); log_action(action, MSG_get_clock() - clock); XBT_INFO("open worker %s%s is done",processid,index); }
int host(int argc, char *argv[]) { int host_number = atoi(MSG_process_get_name(MSG_process_self())); char mailbox[256]; msg_task_t task = NULL; XBT_ATTRIB_UNUSED int res; if (host_number == 0) { //master send then receive sprintf(mailbox, "%d", host_number+1); task = MSG_task_create("Token", task_comp_size, task_comm_size, NULL); XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox); MSG_task_send(task, mailbox); task = NULL; res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self())); xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task)); MSG_task_destroy(task); } else { //slave receive then send res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self())); xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task)); if(host_number+1 == nb_hosts) sprintf(mailbox, "0"); else sprintf(mailbox, "%d", host_number+1); XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox); MSG_task_send(task, mailbox); } return 0; }
static void simcreat(const char *const *action) { const char *processid = action[0]; const char *worktime = action[3]; double sleeptime; const char *index = action[4]; char full_name[1024]; msg_file_t file = NULL; double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */ sleeptime = atof(worktime); MSG_process_sleep(sleeptime); //open slow file const char *file_name = action[2]; char fn[200]; strcpy(fn,file_name); ReplaceStr(fn,"/home","/slow"); sprintf(full_name, "%s:%s:%s:%s","slow",file_name,MSG_process_get_name(MSG_process_self()), index); ACT_DEBUG("Entering Creat: %s (filename: %s)", NAME, file_name); file = MSG_file_open(fn, NULL); xbt_dict_set(opened_files, full_name, file, NULL); //open fast version of file strcpy(fn,file_name); ReplaceStr(fn,"/home","/fast"); sprintf(full_name, "%s:%s:%s:%s","fast",file_name,MSG_process_get_name(MSG_process_self()), index); ACT_DEBUG("Entering Creat: %s (filename: %s)", NAME, file_name); file = MSG_file_open(fn, NULL); xbt_dict_set(opened_files, full_name, file, NULL); log_action(action, MSG_get_clock() - clock); XBT_INFO("creat worker %s %s is done",processid,index); }
static void action_reduce(const char *const *action) { int i; char *reduce_identifier; char mailbox[80]; double comm_size = parse_double(action[2]); double comp_size = parse_double(action[3]); msg_task_t comp_task = NULL; const char *process_name; double clock = MSG_get_clock(); process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self()); xbt_assert(communicator_size, "Size of Communicator is not defined, " "can't use collective operations"); process_name = MSG_process_get_name(MSG_process_self()); reduce_identifier = bprintf("reduce_%d", counters->reduce_counter++); if (!strcmp(process_name, "p0")) { XBT_DEBUG("%s: %s is the Root", reduce_identifier, process_name); msg_comm_t *comms = xbt_new0(msg_comm_t, communicator_size - 1); msg_task_t *tasks = xbt_new0(msg_task_t, communicator_size - 1); for (i = 1; i < communicator_size; i++) { sprintf(mailbox, "%s_p%d_p0", reduce_identifier, i); comms[i - 1] = MSG_task_irecv(&(tasks[i - 1]), mailbox); } MSG_comm_waitall(comms, communicator_size - 1, -1); for (i = 1; i < communicator_size; i++) { MSG_comm_destroy(comms[i - 1]); MSG_task_destroy(tasks[i - 1]); } xbt_free(comms); xbt_free(tasks); comp_task = MSG_task_create("reduce_comp", comp_size, 0, NULL); XBT_DEBUG("%s: computing 'reduce_comp'", reduce_identifier); MSG_task_execute(comp_task); MSG_task_destroy(comp_task); XBT_DEBUG("%s: computed", reduce_identifier); } else { XBT_DEBUG("%s: %s sends", reduce_identifier, process_name); sprintf(mailbox, "%s_%s_p0", reduce_identifier, process_name); XBT_DEBUG("put on %s", mailbox); MSG_task_send(MSG_task_create(reduce_identifier, 0, comm_size, NULL), mailbox); } log_action(action, MSG_get_clock() - clock); xbt_free(reduce_identifier); }
static void action_bcast(const char *const *action) { int i; char *bcast_identifier; char mailbox[80]; double comm_size = parse_double(action[2]); msg_task_t task = NULL; const char *process_name; double clock = MSG_get_clock(); process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self()); xbt_assert(communicator_size, "Size of Communicator is not defined, " "can't use collective operations"); process_name = MSG_process_get_name(MSG_process_self()); bcast_identifier = bprintf("bcast_%d", counters->bcast_counter++); if (!strcmp(process_name, "p0")) { XBT_DEBUG("%s: %s is the Root", bcast_identifier, process_name); msg_comm_t *comms = xbt_new0(msg_comm_t, communicator_size - 1); for (i = 1; i < communicator_size; i++) { sprintf(mailbox, "%s_p0_p%d", bcast_identifier, i); comms[i - 1] = MSG_task_isend(MSG_task_create(mailbox, 0, comm_size, NULL), mailbox); } MSG_comm_waitall(comms, communicator_size - 1, -1); for (i = 1; i < communicator_size; i++) MSG_comm_destroy(comms[i - 1]); xbt_free(comms); XBT_DEBUG("%s: all messages sent by %s have been received", bcast_identifier, process_name); } else { sprintf(mailbox, "%s_p0_%s", bcast_identifier, process_name); MSG_task_receive(&task, mailbox); MSG_task_destroy(task); XBT_DEBUG("%s: %s has received", bcast_identifier, process_name); } log_action(action, MSG_get_clock() - clock); xbt_free(bcast_identifier); }
int computation_fun(int argc, char *argv[]) { const char *pr_name = MSG_process_get_name(MSG_process_self()); const char *host_name = MSG_host_get_name(MSG_host_self()); double clock_sta, clock_end; atask = MSG_task_create("Task1", 1e9, 1e9, NULL); clock_sta = MSG_get_clock(); XBT_INFO("%s:%s task 1 created %g", host_name, pr_name, clock_sta); MSG_task_execute(atask); clock_end = MSG_get_clock(); XBT_INFO("%s:%s task 1 executed %g", host_name, pr_name, clock_end - clock_sta); MSG_task_destroy(atask); atask = NULL; MSG_process_sleep(1); atask = MSG_task_create("Task2", 1e10, 1e10, NULL); clock_sta = MSG_get_clock(); XBT_INFO("%s:%s task 2 created %g", host_name, pr_name, clock_sta); MSG_task_execute(atask); clock_end = MSG_get_clock(); XBT_INFO("%s:%s task 2 executed %g", host_name, pr_name, clock_end - clock_sta); MSG_task_destroy(atask); atask = NULL; return 0; }
/** * \brief Runs a Lua function as a new simulated process. * \param argc number of arguments of the function * \param argv name of the Lua function and array of its arguments * \return result of the function */ static int run_lua_code(int argc, char **argv) { XBT_DEBUG("Run lua code %s", argv[0]); /* create a new state, getting globals from maestro */ lua_State *L = sglua_clone_maestro(); MSG_process_set_data(MSG_process_self(), L); /* start the function */ lua_getglobal(L, argv[0]); xbt_assert(lua_isfunction(L, -1), "There is no Lua function with name `%s'", argv[0]); /* push arguments onto the stack */ int i; for (i = 1; i < argc; i++) lua_pushstring(L, argv[i]); /* call the function */ _XBT_GNUC_UNUSED int err; err = lua_pcall(L, argc - 1, 1, 0); xbt_assert(err == 0, "Error running function `%s': %s", argv[0], lua_tostring(L, -1)); /* retrieve result */ int res = 1; if (lua_isnumber(L, -1)) { res = lua_tonumber(L, -1); lua_pop(L, 1); /* pop returned value */ } XBT_DEBUG("Execution of Lua code %s is over", (argv ? argv[0] : "(null)")); return res; }
static int client(int argc, char *argv[]) { int my_pid = MSG_process_get_PID(MSG_process_self()); char *my_mailbox = xbt_strdup(argv[1]); while(1){ XBT_INFO("Client (%s) asks the request", my_mailbox); MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator"); msg_task_t answer = NULL; MSG_task_receive(&answer, my_mailbox); const char* kind = MSG_task_get_name(answer); if (!strcmp(kind, "grant")) { XBT_INFO("Client (%s) got the answer (grant). Sleep a bit and release it", my_mailbox); if(!strcmp(my_mailbox, "1")) cs = 1; }else{ XBT_INFO("Client (%s) got the answer (not grant). Try again", my_mailbox); } MSG_task_destroy(answer); kind = NULL; MSG_process_sleep(my_pid); } return 0; }
/** * \brief Blocks the current process until a communication is finished. * \param L a Lua state * \return number of values returned to Lua * * - Argument 1 (comm): a comm (previously created by isend or irecv) * - Argument 2 (number, optional): timeout (default is no timeout) * - Return values (task or nil + string): in case of success, returns the task * received if you are the receiver and nil if you are the sender. In case of * failure, returns nil plus an error string. */ static int l_comm_wait(lua_State* L) { msg_comm_t comm = sglua_check_comm(L, 1); double timeout = -1; if (lua_gettop(L) >= 2) { timeout = luaL_checknumber(L, 2); } /* comm ... */ msg_error_t res = MSG_comm_wait(comm, timeout); if (res == MSG_OK) { msg_task_t task = MSG_comm_get_task(comm); if (MSG_task_get_sender(task) == MSG_process_self()) { /* I'm the sender */ return 0; } else { /* I'm the receiver: find the Lua task from the C task */ sglua_task_unregister(L, task); /* comm ... task */ return 1; } } else { /* the communication has failed */ lua_pushnil(L); /* comm ... nil */ lua_pushstring(L, sglua_get_msg_error(res)); /* comm ... nil error */ return 2; } }
int uploader(int argc, char* argv[]){ /** @type simgrid process Uploads output file to another host. Simgrid process parameters -------------------------- UploadData* data -- pointer to object which contains inforamation about how to replicate output file. (destination host, filename, etc.) */ std::string host_name = MSG_host_get_name(MSG_host_self()); std::string curFilePath; std::string pathAtDest; std::string destHostName; std::string stor_type; msg_file_t file = NULL; UploadData* data = (UploadData*) MSG_process_get_data(MSG_process_self()); destHostName = data->dest; destHostName.erase(destHostName.length()-5); stor_type = data->dest.back(); if (destHostName.compare(host_name)) { curFilePath = "/" + host_name + "-DISK" + data->filename; pathAtDest = "/" + data->dest + data->filename; file = MSG_file_open(curFilePath.c_str(), NULL); msg_host_t dest = MSG_host_by_name(destHostName.c_str()); //plusLinkCounter(MSG_host_get_name(MSG_host_self()), destHostName); msg_error_t a = MSG_file_rcopy(file, dest, pathAtDest.c_str()); //if (!atoi(stor_type.c_str())) create_file_label(pathAtDest); //trace number of datasets and output traffic from site dataset_number_change(data->dest, 1); cumulative_output_per_site(host_name, (double) MSG_file_get_size(file)); if (a == MSG_OK) { tracer_traffic(host_name, destHostName, (double) MSG_file_get_size(file)); minusLinkCounter(host_name, destHostName); MSG_file_close(file); //XBT_INFO("Creating replica completed at %s", MSG_host_get_name(dest)); } else { minusLinkCounter(host_name, destHostName); MSG_file_close(file); XBT_INFO("Transfer fail occurred"); } } delete data; return 0; }
msg_file_t get_file_descriptor(const char *file_name,const char *index){//get file with the file full_name char full_name[1024]; msg_file_t file = NULL; sprintf(full_name, "%s:%s:%s", file_name,MSG_process_get_name(MSG_process_self()),index); file = (msg_file_t) xbt_dict_get_or_null(opened_files, full_name); return file; }
/** Receiver function */ int worker(int argc, char *argv[]) { msg_task_t task = NULL; _XBT_GNUC_UNUSED int res; char channel[1024]; build_channel_name(channel,MSG_process_get_data(MSG_process_self()), MSG_host_get_name(MSG_host_self())); XBT_DEBUG("Receiving on channel \"%s\"", channel); while (1) { res = MSG_task_receive(&(task),channel); xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_DEBUG("Received \"%s\"", MSG_task_get_name(task)); if (!strcmp(MSG_task_get_name(task), "finalize")) { MSG_task_destroy(task); break; } XBT_DEBUG("Processing \"%s\"", MSG_task_get_name(task)); MSG_task_execute(task); XBT_DEBUG("\"%s\" done", MSG_task_get_name(task)); MSG_task_destroy(task); task = NULL; } XBT_DEBUG("I'm done. See you!"); return 0; } /* end_of_worker */
/* Internal function used to factorize code between * MSG_task_isend_with_matching() and MSG_task_dsend(). */ static XBT_INLINE msg_comm_t MSG_task_isend_internal(msg_task_t task, const char *alias, int (*match_fun)(void*,void*, smx_synchro_t), void *match_data, void_f_pvoid_t cleanup, int detached) { simdata_task_t t_simdata = NULL; msg_process_t process = MSG_process_self(); msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias); int call_end = TRACE_msg_task_put_start(task); /* Prepare the task to send */ t_simdata = task->simdata; t_simdata->sender = process; t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host; if (t_simdata->isused != 0) { if (msg_global->debug_multiple_use){ XBT_ERROR("This task is already used in there:"); xbt_backtrace_display(t_simdata->isused); XBT_ERROR("And you try to reuse it from here:"); xbt_backtrace_display_current(); } else { xbt_assert(t_simdata->isused == 0, "This task is still being used somewhere else. You cannot send it now. Go fix your code! (use --cfg=msg/debug_multiple_use:on to get the backtrace of the other process)"); } } if (msg_global->debug_multiple_use) MSG_BT(t_simdata->isused, "Using Backtrace"); else t_simdata->isused = (void*)1; t_simdata->comm = NULL; msg_global->sent_msg++; /* Send it by calling SIMIX network layer */ smx_synchro_t act = simcall_comm_isend(SIMIX_process_self(), mailbox, t_simdata->bytes_amount, t_simdata->rate, task, sizeof(void *), match_fun, cleanup, NULL, match_data,detached); t_simdata->comm = act; /* FIXME: is the field t_simdata->comm still useful? */ msg_comm_t comm; if (detached) { comm = NULL; } else { comm = xbt_new0(s_msg_comm_t, 1); comm->task_sent = task; comm->task_received = NULL; comm->status = MSG_OK; comm->s_comm = act; } if (TRACE_is_enabled()) simcall_set_category(act, task->category); if (call_end) TRACE_msg_task_put_end(); return comm; }
static void action_Isend(const char *const *action) { char to[250]; const char *size = action[3]; double clock = MSG_get_clock(); process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), action[2]); msg_comm_t comm = MSG_task_isend(MSG_task_create(to, 0, parse_double(size), NULL), to); xbt_dynar_push(globals->isends, &comm); XBT_DEBUG("Isend on %s", MSG_process_get_name(MSG_process_self())); log_action(action, MSG_get_clock() - clock); asynchronous_cleanup(); }
static int worker_busy_loop_main(int argc, char *argv[]) { msg_task_t *task = MSG_process_get_data(MSG_process_self()); MSG_task_execute(*task); MSG_task_destroy(*task); return 0; }
/** Victim. This process gets a lot of remote exceptions */ static int victim(int argc, char *argv[]) { xbt_ex_t e; msg_error_t res = MSG_OK; XBT_INFO("Let's work."); TRY { res = MSG_task_execute(MSG_task_create("Task", 1e14, 0, NULL)); if (res != MSG_OK) { XBT_INFO("The MSG_task_execute caught the exception for me and returned %d)",res); } else { xbt_die("I was expecting an exception during my execution!"); } } CATCH(e) { XBT_INFO("The received exception resumed my execution. Good. Here is it: ----------------------->8----"); xbt_ex_display(&e); XBT_INFO("(end of the first exception) ----8<------------------------"); xbt_ex_free(e); } XBT_INFO("Let's get suspended."); int gotit = 0; TRY { MSG_process_suspend(MSG_process_self()); } CATCH(e) { XBT_INFO("The received exception resumed my suspension. Good. Here is it: ----------------------->8----"); xbt_ex_display(&e); XBT_INFO("(end of the second exception) ----8<------------------------"); gotit = 1; xbt_ex_free(e); } if(!gotit) { xbt_die("I was expecting an exception during my suspension!"); } XBT_INFO("Let's sleep for 10 seconds."); TRY { res = MSG_process_sleep(10); if (res != MSG_OK) { XBT_INFO("The MSG_process_sleep caught the exception for me and returned %d)",res); } else { xbt_die("I was expecting to get an exception during my nap."); } } CATCH(e) { XBT_INFO("Got the second exception: ----------------------->8----"); xbt_ex_display(&e); XBT_INFO("(end of the third exception) ----8<------------------------"); xbt_ex_free(e); } XBT_INFO("Let's try a last time to do something on something"); MSG_process_sleep(10); XBT_INFO("That's enough now. I quit."); return 0; }
static msg_file_t get_file_descriptor(const char *file_name){ char full_name[1024]; msg_file_t file = NULL; snprintf(full_name,1023, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name); file = (msg_file_t) xbt_dict_get_or_null(opened_files, full_name); return file; }
int master_fun(int argc, char *argv[]) { msg_vm_t vm; unsigned int i; xbt_dynar_t worker_pms = MSG_process_get_data(MSG_process_self()); int nb_workers = xbt_dynar_length(worker_pms); xbt_dynar_t vms = xbt_dynar_new(sizeof(msg_vm_t), NULL); /* Launch VMs and worker processes. One VM per PM, and one worker process per VM. */ XBT_INFO("# Launch %d VMs", nb_workers); for (i = 0; i< nb_workers; i++) { char *vm_name = bprintf("VM%02d", i); char *pr_name = bprintf("WRK%02d", i); msg_host_t pm = xbt_dynar_get_as(worker_pms, i, msg_host_t); XBT_INFO("create %s on PM(%s)", vm_name, MSG_host_get_name(pm)); msg_vm_t vm = MSG_vm_create_core(pm, vm_name); s_vm_params_t params; memset(¶ms, 0, sizeof(params)); params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes MSG_host_set_params(vm, ¶ms); MSG_vm_start(vm); xbt_dynar_push(vms, &vm); XBT_INFO("put a process (%s) on %s", pr_name, vm_name); MSG_process_create(pr_name, worker_fun, NULL, vm); xbt_free(vm_name); xbt_free(pr_name); } /* Send a bunch of work to every one */ XBT_INFO("# Send a task to %d worker process", nb_workers); send_tasks(nb_workers); XBT_INFO("# Suspend all VMs"); xbt_dynar_foreach(vms, i, vm) { const char *vm_name = MSG_host_get_name(vm); XBT_INFO("suspend %s", vm_name); MSG_vm_suspend(vm); } XBT_INFO("# Wait a while"); MSG_process_sleep(2); XBT_INFO("# Resume all VMs"); xbt_dynar_foreach(vms, i, vm) { MSG_vm_resume(vm); }
static int victim(int argc, char *argv[]) { XBT_INFO("Hello!"); XBT_INFO("Suspending myself"); MSG_process_suspend(MSG_process_self()); /* - First suspend itself */ XBT_INFO("OK, OK. Let's work"); /* - Then is resumed and start to execute a task */ MSG_task_execute(MSG_task_create("work", 1e9, 0, NULL)); XBT_INFO("Bye!"); /* - But will never reach the end of it */ return 0; }
static int worker_main(int argc, char *argv[]) { msg_task_t task = (msg_task_t) MSG_process_get_data(MSG_process_self()); msg_error_t res; XBT_INFO("Start %s", task->name); res = MSG_task_execute(task); XBT_INFO("Task %s", res == MSG_OK ? "done" : "failed"); MSG_task_destroy(task); return 0; }
static void action_init(const char *const *action) { XBT_DEBUG("Initialize the counters"); process_globals_t globals = (process_globals_t) calloc(1, sizeof(s_process_globals_t)); globals->isends = xbt_dynar_new(sizeof(msg_comm_t), NULL); globals->irecvs = xbt_dynar_new(sizeof(msg_comm_t), NULL); globals->tasks = xbt_dynar_new(sizeof(msg_task_t), NULL); MSG_process_set_data(MSG_process_self(), globals); }
static int slave(int argc, char *argv[]) { MSG_process_sleep(.5); XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID()); while(1) { XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not "); MSG_process_sleep(1); } XBT_INFO("I'm done. See you!"); return 0; }
/** \ingroup msg_task_usage * \brief Executes a task and waits for its termination. * * This function is used for describing the behavior of a process. It * takes only one parameter. * \param task a #msg_task_t to execute on the location on which the process is running. * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED * or #MSG_HOST_FAILURE otherwise */ msg_error_t MSG_task_execute(msg_task_t task) { /* TODO: add this to other locations */ msg_host_t host = MSG_process_get_host(MSG_process_self()); MSG_host_add_task(host, task); msg_error_t ret = MSG_parallel_task_execute(task); MSG_host_del_task(host, task); return ret; }
static void action_finalize(const char *const *action) { process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); if (globals) { asynchronous_cleanup(); xbt_dynar_free_container(&(globals->isends)); xbt_dynar_free_container(&(globals->irecvs)); xbt_dynar_free_container(&(globals->tasks)); xbt_free(globals); } }
/** The guy we will move from host to host. It move alone and then is moved by policeman back */ static int emigrant(int argc, char *argv[]) { msg_task_t task; XBT_INFO ("I'll look for a new job on another machine where the grass is greener."); MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin")); XBT_INFO("Yeah, found something to do"); task = MSG_task_create("job", 98095000, 0, NULL); MSG_task_execute(task); MSG_task_destroy(task); MSG_process_sleep(2); XBT_INFO("Moving back home after work"); MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Jacquelin")); MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin")); MSG_process_sleep(4); xbt_mutex_acquire(mutex); process_to_migrate = MSG_process_self(); xbt_cond_broadcast(cond); xbt_mutex_release(mutex); MSG_process_suspend(MSG_process_self()); msg_host_t h = MSG_process_get_host(MSG_process_self()); XBT_INFO("I've been moved on this new host: %s", MSG_host_get_name(h)); XBT_INFO("Uh, nothing to do here. Stopping now"); return 0; } /* end_of_emigrant */
void TRACE_msg_task_execute_end(msg_task_t task) { XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category); if (TRACE_msg_process_is_enabled()){ int len = INSTR_DEFAULT_STR_SIZE; char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len)); type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type); new_pajePopState (MSG_get_clock(), process_container, type); } }
void TRACE_msg_task_put_end(void) { XBT_DEBUG("PUT,out"); if (TRACE_msg_process_is_enabled()){ int len = INSTR_DEFAULT_STR_SIZE; char str[INSTR_DEFAULT_STR_SIZE]; container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len)); type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type); new_pajePopState (MSG_get_clock(), process_container, type); } }
static void asynchronous_cleanup(void) { process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self()); /* Destroy any isend which correspond to completed communications */ int found; msg_comm_t comm; while ((found = MSG_comm_testany(globals->isends)) != -1) { xbt_dynar_remove_at(globals->isends, found, &comm); MSG_comm_destroy(comm); } }