static int host(int argc, char *argv[]) { char name[2048]; int id = MSG_process_self_PID(); snprintf(name,2048,"%s%i", FILENAME1, id); msg_file_t file = MSG_file_open(name, NULL); XBT_INFO("process %d is writing!", id); MSG_file_write(file, 3000000); XBT_INFO("process %d goes to sleep for %d seconds", id, id); MSG_process_sleep(id); XBT_INFO("process %d is writing again!", id); MSG_file_write(file, 3000000); XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id); MSG_process_sleep(6-id); XBT_INFO("process %d is reading!", id); MSG_file_seek(file, 0, SEEK_SET); MSG_file_read(file, 3000000); XBT_INFO("process %d goes to sleep for %d seconds", id, id); MSG_process_sleep(id); XBT_INFO("process %d is reading again!", id); MSG_file_seek(file, 0, SEEK_SET); MSG_file_read(file, 3000000); XBT_INFO("process %d => Size of %s: %llu", id, MSG_file_get_name(file), MSG_file_get_size(file)); MSG_file_close(file); return 0; }
static int master(int argc, char *argv[]) { xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self()); msg_process_t process = NULL; MSG_process_sleep(1); xbt_swag_foreach(process, process_list) { XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process), MSG_process_get_name(process)); if (MSG_process_self_PID() != MSG_process_get_PID(process)) MSG_process_kill(process); }
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_file_management * \brief Close the file * * \param fd is the file to close * \return 0 on success or 1 on error */ int MSG_file_close(msg_file_t fd) { char *name; msg_file_priv_t priv = MSG_file_priv(fd); if (priv->data) xbt_free(priv->data); int res = simcall_file_close(priv->simdata->smx_file, MSG_host_self()); name = bprintf("%s:%i:%s",MSG_host_get_name(MSG_host_self()),MSG_process_self_PID(),priv->fullpath); xbt_lib_unset(file_lib, name, MSG_FILE_LEVEL, 1); xbt_free(name); return res; }
/** \ingroup msg_file_management * \brief Opens the file whose name is the string pointed to by path * * \param fullpath is the file location on the storage * \param data user data to attach to the file * * \return An #msg_file_t associated to the file */ msg_file_t MSG_file_open(const char* fullpath, void* data) { char *name; msg_file_priv_t priv = xbt_new(s_msg_file_priv_t, 1); priv->data = data; priv->fullpath = xbt_strdup(fullpath); priv->simdata = xbt_new0(s_simdata_file_t,1); priv->simdata->smx_file = simcall_file_open(fullpath, MSG_host_self()); name = bprintf("%s:%i:%s",MSG_host_get_name(MSG_host_self()),MSG_process_self_PID(),fullpath); xbt_lib_set(file_lib, name, MSG_FILE_LEVEL, priv); msg_file_t fd = (msg_file_t) xbt_lib_get_elm_or_null(file_lib, name); __MSG_file_get_info(fd); xbt_free(name); return fd; }
static int host(int argc, char *argv[]) { msg_file_t file = NULL; sg_size_t read; sg_size_t write; msg_storage_t st; const char* st_name; switch(MSG_process_self_PID()){ case 1: file = MSG_file_open(FILENAME1, NULL); MSG_file_dump(file); st_name = "Disk4"; break; case 2 : file = MSG_file_open(FILENAME2, NULL); st_name = "Disk2"; break; case 3 : file = MSG_file_open(FILENAME3, NULL); st_name = "Disk3"; break; case 4: file = MSG_file_open(FILENAME4, NULL); st_name = "Disk1"; break; default: xbt_die("FILENAME NOT DEFINED %s",MSG_process_get_name(MSG_process_self())); } const char* filename = MSG_file_get_name(file); XBT_INFO("\tOpen file '%s'",filename); st = MSG_storage_get_by_name(st_name); XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu", filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st)); /* Try to read for 10MB */ read = MSG_file_read(file, 10000000); XBT_INFO("\tHave read %llu from '%s'",read,filename); /* Write 100KB in file from the current position, i.e, end of file or 10MB */ write = MSG_file_write(file, 100000); XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu",write,filename, MSG_file_get_size(file)); XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu", filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st)); /* rewind to the beginning of the file */ XBT_INFO("\tComing back to the beginning of the stream for file '%s'", filename); MSG_file_seek(file, 0, SEEK_SET); /* Try to read 110KB */ read = MSG_file_read(file, 110000); XBT_INFO("\tHave read %llu from '%s' (of size %llu)",read,filename, MSG_file_get_size(file)); /* rewind once again to the beginning of the file */ XBT_INFO("\tComing back to the beginning of the stream for file '%s'", filename); MSG_file_seek(file, 0, SEEK_SET); /* Write 110KB in file from the current position, i.e, end of file or 10MB */ write = MSG_file_write(file, 110000); XBT_INFO("\tHave written %llu in '%s'. Size now is: %llu", write,filename, MSG_file_get_size(file)); XBT_INFO("\tCapacity of the storage element '%s' is stored on: %llu / %llu", filename, MSG_storage_get_used_size(st), MSG_storage_get_size(st)); if (MSG_process_self_PID() == 1){ XBT_INFO("\tUnlink file '%s'",MSG_file_get_name(file)); MSG_file_unlink(file); } else { XBT_INFO("\tClose file '%s'",filename); MSG_file_close(file); } return 0; }