#include <stdio.h>
#include "smpi/smpi.h"
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
smpi_replay_init(&argc, &argv);
-
- /* Actually do the simulation using smpi_action_trace_run */
- smpi_action_trace_run(NULL);
smpi_replay_finalize();
-
return 0;
}
#include "xbt/asserts.h"
#include "smpi/smpi.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
-
+ "Messages specific for this msg example");
+
int smpi_replay(int argc, char *argv[]);
int smpi_replay(int argc, char *argv[])
{
- smpi_replay_init(&argc, &argv);
-
- /* Actually do the simulation using smpi_action_trace_run */
- smpi_action_trace_run(NULL);
- smpi_replay_finalize();
-
- return 0;
+ smpi_replay_init(&argc, &argv);
+ smpi_replay_finalize();
+ return 0;
}
int main(int argc, char *argv[]){
- msg_error_t res;
- const char *platform_file;
- const char *application_file;
- const char *description_file;
-
- MSG_init(&argc, argv);
-
- if (argc < 4) {
- printf("Usage: %s description_file platform_file deployment_file\n", argv[0]);
- printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]);
- exit(1);
- }
- description_file = argv[1];
- platform_file = argv[2];
- application_file = argv[3];
-
-
- { /* Simulation setting */
- MSG_create_environment(platform_file);
- }
- { /* Application deployment */
- //read the description file in order to identify instances to launch
- FILE* fp = fopen(description_file, "r");
- if (fp == NULL)
- xbt_die("Cannot open %s", description_file);
- ssize_t read;
- char *line = NULL;
- size_t n = 0;
- int instance_size = 0;
- const char* instance_id = NULL;
- while ((read = xbt_getline(&line, &n, fp)) != -1 ){
- xbt_dynar_t elems = xbt_str_split_quoted_in_place(line);
- if(xbt_dynar_length(elems)<3){
- xbt_die ("Not enough elements in the line");
- }
-
- const char** line_char= xbt_dynar_to_array(elems);
- instance_id = line_char[0];
- instance_size = atoi(line_char[2]);
-
- XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
- SMPI_app_instance_register(instance_id, smpi_replay,instance_size);
-
- xbt_free(line_char);
- }
-
- MSG_launch_application(application_file);
- SMPI_init();
- }
- res = MSG_main();
-
- XBT_INFO("Simulation time %g", MSG_get_clock());
-
-
- SMPI_finalize();
- if (res == MSG_OK)
- return 0;
- else
- return 1;
+ msg_error_t res;
+ const char *platform_file;
+ const char *application_file;
+ const char *description_file;
+
+ MSG_init(&argc, argv);
+
+ if (argc < 4) {
+ printf("Usage: %s description_file platform_file deployment_file\n", argv[0]);
+ printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]);
+ exit(1);
+ }
+ description_file = argv[1];
+ platform_file = argv[2];
+ application_file = argv[3];
+
+
+ /* Simulation setting */
+ MSG_create_environment(platform_file);
+
+ /* Application deployment: read the description file in order to identify instances to launch */
+ FILE* fp = fopen(description_file, "r");
+ if (fp == NULL)
+ xbt_die("Cannot open %s", description_file);
+ ssize_t read;
+ char *line = NULL;
+ size_t n = 0;
+ int instance_size = 0;
+ const char* instance_id = NULL;
+ while ((read = xbt_getline(&line, &n, fp)) != -1 ){
+ xbt_dynar_t elems = xbt_str_split_quoted_in_place(line);
+ if(xbt_dynar_length(elems)<3){
+ xbt_die ("Not enough elements in the line");
+ }
+
+ const char** line_char= xbt_dynar_to_array(elems);
+ instance_id = line_char[0];
+ instance_size = atoi(line_char[2]);
+
+ XBT_INFO("Initializing instance %s of size %d", instance_id, instance_size);
+ SMPI_app_instance_register(instance_id, smpi_replay,instance_size);
+
+ xbt_free(line_char);
+ }
+
+ MSG_launch_application(application_file);
+ SMPI_init();
+
+ res = MSG_main();
+
+ XBT_INFO("Simulation time %g", MSG_get_clock());
+
+ SMPI_finalize();
+ if (res == MSG_OK)
+ return 0;
+ else
+ return 1;
}
/* Trace replay specific stuff */
XBT_PUBLIC(void) smpi_replay_init(int *argc, char***argv);
-XBT_PUBLIC(void) smpi_action_trace_run(char *);
XBT_PUBLIC(int) smpi_replay_finalize(void);
XBT_PUBLIC(void) SMPI_app_instance_register(const char *name, xbt_main_func_t code, int num_processes);
typedef struct s_replay_reader *xbt_replay_reader_t;
typedef void (*action_fun) (const char *const *args);
-XBT_PUBLIC_DATA(xbt_dict_t) action_funs;
-XBT_PUBLIC_DATA(xbt_dict_t) action_queues;
+XBT_PUBLIC_DATA(xbt_dict_t) xbt_action_funs;
+XBT_PUBLIC_DATA(xbt_dict_t) xbt_action_queues;
/* To split the file if a unique one is given (specific variable for the other case live in runner()) */
-XBT_PUBLIC_DATA(FILE *) action_fp;
+XBT_PUBLIC_DATA(FILE *) xbt_action_fp;
XBT_PUBLIC(xbt_replay_reader_t) xbt_replay_reader_new(const char*filename);
XBT_PUBLIC(const char **) xbt_replay_reader_get(xbt_replay_reader_t reader);
xbt_dynar_t todo;
xbt_dict_cursor_t cursor;
- action_fp=NULL;
+ xbt_action_fp=NULL;
if (path) {
- action_fp = fopen(path, "r");
- if (action_fp == NULL)
+ 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(action_queues)) {
+ 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(action_queues, cursor, name, todo) {
+ xbt_dict_foreach(xbt_action_queues, cursor, name, todo) {
XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name);
}
}
if (path)
- fclose(action_fp);
- xbt_dict_free(&action_queues);
- action_queues = xbt_dict_new_homogeneous(NULL);
+ fclose(xbt_action_fp);
+ xbt_dict_free(&xbt_action_queues);
+ xbt_action_queues = xbt_dict_new_homogeneous(NULL);
return res;
}
}
}
-void smpi_action_trace_run(char *path)
-{
- char *name;
- xbt_dynar_t todo;
- xbt_dict_cursor_t cursor;
-
- action_fp=NULL;
- if (path) {
- action_fp = fopen(path, "r");
- if (action_fp == NULL)
- xbt_die("Cannot open %s: %s", path, strerror(errno));
- }
-
- if (!xbt_dict_is_empty(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(action_queues, cursor, name, todo) {
- XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name);
- }
- }
-
- if (path)
- fclose(action_fp);
- xbt_dict_free(&action_queues);
- action_queues = xbt_dict_new_homogeneous(NULL);
-}
-
static void smpi_mpi_request_free_voidp(void* request)
{
MPI_Request req = request;
XBT_VERB("Delayed start for instance - Sleeping for %f flops ",value );
smpi_execute_flops(value);
} else {
- //UGLY done to force context switch to be sure that all MSG_processes begin initialization
+ //UGLY: force a context switch to be sure that all MSG_processes begin initialization
XBT_DEBUG("Force context switch by smpi_execute_flops - Sleeping for 0.0 flops ");
smpi_execute_flops(0.0);
}
int linenum;
} s_xbt_replay_reader_t;
-FILE *action_fp;
+FILE *xbt_action_fp;
-xbt_dict_t action_funs = NULL;
-xbt_dict_t action_queues = NULL;
+xbt_dict_t xbt_action_funs = NULL;
+xbt_dict_t xbt_action_queues = NULL;
static char *action_line = NULL;
static size_t action_len = 0;
void xbt_replay_action_register(const char *action_name, action_fun function)
{
char* lowername = str_tolower (action_name);
- xbt_dict_set(action_funs, lowername, function, NULL);
+ xbt_dict_set(xbt_action_funs, lowername, function, NULL);
xbt_free(lowername);
}
void xbt_replay_action_unregister(const char *action_name)
{
char* lowername = str_tolower (action_name);
- xbt_dict_remove(action_funs, lowername);
+ xbt_dict_remove(xbt_action_funs, lowername);
xbt_free(lowername);
}
*/
int _xbt_replay_action_init(void)
{
- if (action_funs)
+ if (xbt_action_funs)
return 0;
is_replay_active = 1;
- action_funs = xbt_dict_new_homogeneous(NULL);
- action_queues = xbt_dict_new_homogeneous(NULL);
+ xbt_action_funs = xbt_dict_new_homogeneous(NULL);
+ xbt_action_queues = xbt_dict_new_homogeneous(NULL);
return 1;
}
void _xbt_replay_action_exit(void)
{
- xbt_dict_free(&action_queues);
- xbt_dict_free(&action_funs);
+ xbt_dict_free(&xbt_action_queues);
+ xbt_dict_free(&xbt_action_funs);
free(action_line);
- action_queues = NULL;
- action_funs = NULL;
+ xbt_action_queues = NULL;
+ xbt_action_funs = NULL;
action_line = NULL;
}
{
int i;
xbt_ex_t e;
- if (action_fp) { // A unique trace file
+ if (xbt_action_fp) { // A unique trace file
char **evt;
while ((evt = action_get_action(argv[0]))) {
char* lowername = str_tolower (evt[1]);
action_fun function =
- (action_fun)xbt_dict_get(action_funs, lowername);
+ (action_fun)xbt_dict_get(xbt_action_funs, lowername);
xbt_free(lowername);
TRY{
function((const char **)evt);
while ((evt=xbt_replay_reader_get(reader))) {
if (!strcmp(argv[0],evt[0])) {
char* lowername = str_tolower (evt[1]);
- action_fun function = (action_fun)xbt_dict_get(action_funs, lowername);
+ action_fun function = (action_fun)xbt_dict_get(xbt_action_funs, lowername);
xbt_free(lowername);
TRY{
function(evt);
xbt_dynar_t evt = NULL;
char *evtname = NULL;
- xbt_dynar_t myqueue = xbt_dict_get_or_null(action_queues, name);
+ xbt_dynar_t myqueue = xbt_dict_get_or_null(xbt_action_queues, name);
if (myqueue == NULL || xbt_dynar_is_empty(myqueue)) { // nothing stored for me. Read the file further
- if (action_fp == NULL) { // File closed now. There's nothing more to read. I'm out of here
+ if (xbt_action_fp == NULL) { // File closed now. There's nothing more to read. I'm out of here
goto todo_done;
}
// Read lines until I reach something for me (which breaks in loop body)
// or end of file reached
- while (xbt_getline(&action_line, &action_len, action_fp) != -1) {
+ while (xbt_getline(&action_line, &action_len, xbt_action_fp) != -1) {
// cleanup and split the string I just read
char *comment = strchr(action_line, '#');
if (comment != NULL)
} else {
// Else, I have to store it for the relevant colleague
xbt_dynar_t otherqueue =
- xbt_dict_get_or_null(action_queues, evtname);
+ xbt_dict_get_or_null(xbt_action_queues, evtname);
if (otherqueue == NULL) { // Damn. Create the queue of that guy
otherqueue =
xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
- xbt_dict_set(action_queues, evtname, otherqueue, NULL);
+ xbt_dict_set(xbt_action_queues, evtname, otherqueue, NULL);
}
xbt_dynar_push(otherqueue, &evt);
}
todo_done:
if (myqueue != NULL) {
xbt_dynar_free(&myqueue);
- xbt_dict_remove(action_queues, name);
+ xbt_dict_remove(xbt_action_queues, name);
}
return NULL;
}