本文整理汇总了C++中MSG_process_self函数的典型用法代码示例。如果您正苦于以下问题:C++ MSG_process_self函数的具体用法?C++ MSG_process_self怎么用?C++ MSG_process_self使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MSG_process_self函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_code
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;
}
示例2: MSG_process_sleep
/** \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);
}
示例3: simopen
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);
}
示例4: host
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;
}
示例5: simcreat
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);
}
示例6: action_reduce
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);
}
示例7: action_bcast
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);
}
示例8: computation_fun
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;
}
示例9: run_lua_code
/**
* \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;
}
示例10: client
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;
}
示例11: l_comm_wait
/**
* \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;
}
}
示例12: uploader
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;
}
示例13: get_file_descriptor
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;
}
示例14: worker
/** 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 */
示例15: MSG_task_isend_internal
/* 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;
}