Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revalidate the tesh file
[simgrid.git] / examples / msg / app-pmm / app-pmm.c
index d6ee681..e68636f 100644 (file)
@@ -20,9 +20,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_pmm, "Messages specific for this msg example");
 #define MAILBOX_NAME_SIZE 10
 #define NEIGHBOURS_COUNT GRID_SIZE - 1
 
-/*
- * The job sent to every node
- */
+/* The job sent to every node */
 typedef struct s_node_job{
   int row;
   int col;
@@ -30,16 +28,18 @@ typedef struct s_node_job{
   int nodes_in_col[NEIGHBOURS_COUNT];
   xbt_matrix_t A;
   xbt_matrix_t B;
-} s_node_job_t, *node_job_t;
+} s_node_job_t;
 
-/*
- * Structure for recovering results
- */
+typedef s_node_job_t *node_job_t;
+
+/* Structure for recovering results */
 typedef struct s_result {
   int row;
   int col;
   xbt_matrix_t sC;
-} s_result_t, *result_t;
+} s_result_t;
+
+typedef s_result_t *result_t;
 
 int node(int argc, char **argv);
 static void create_jobs(xbt_matrix_t A, xbt_matrix_t B, node_job_t *jobs);
@@ -53,8 +53,11 @@ static void task_cleanup(void *arg);
 int node(int argc, char **argv)
 {
   char my_mbox[MAILBOX_NAME_SIZE];
-  node_job_t myjob, jobs[GRID_NUM_NODES];
-  xbt_matrix_t A, B, C, sA, sB, sC;
+  node_job_t myjob;
+  node_job_t jobs[GRID_NUM_NODES];
+  xbt_matrix_t A = NULL;
+  xbt_matrix_t B = NULL;
+  xbt_matrix_t C = NULL;
   result_t result;
 
   xbt_assert(argc != 1, "Wrong number of arguments for this node");
@@ -62,9 +65,9 @@ int node(int argc, char **argv)
   /* Initialize the node's data-structures */
   int myid = xbt_str_parse_int(argv[1], "Invalid ID received as first node parameter: %s");
   snprintf(my_mbox, MAILBOX_NAME_SIZE - 1, "%d", myid);
-  sC = xbt_matrix_double_new_zeros(NODE_MATRIX_SIZE, NODE_MATRIX_SIZE);
+  xbt_matrix_t sC = xbt_matrix_double_new_zeros(NODE_MATRIX_SIZE, NODE_MATRIX_SIZE);
 
-  if(myid == 0){
+  if (myid == 0){
     /* Create the matrices to multiply and one to store the result */
     A = xbt_matrix_double_new_id(MATRIX_SIZE, MATRIX_SIZE);
     B = xbt_matrix_double_new_seq(MATRIX_SIZE, MATRIX_SIZE);
@@ -80,13 +83,15 @@ int node(int argc, char **argv)
     broadcast_jobs(jobs + 1);
 
   } else {
-    A = B = C = NULL;           /* Avoid warning at compilation */
     myjob = wait_job(myid);
   }
 
   /* Multiplication main-loop */
   XBT_VERB("Start Multiplication's Main-loop");
   for (int k=0; k < GRID_SIZE; k++){
+    xbt_matrix_t sA;
+    xbt_matrix_t sB;
+
     if(k == myjob->col){
       XBT_VERB("Broadcast sA(%d,%d) to row %d", myjob->row, k, myjob->row);
       broadcast_matrix(myjob->A, NEIGHBOURS_COUNT, myjob->nodes_in_row);
@@ -236,10 +241,11 @@ static void task_cleanup(void *arg){
 
 int main(int argc, char *argv[])
 {
-  xbt_os_timer_t timer = xbt_os_timer_new();
-
   MSG_init(&argc, argv);
-  MSG_create_environment(argv[1]);
+  const char *platform = "../../platforms/cluster.xml";
+  if (argc > 1)
+     platform = argv[1];
+  MSG_create_environment(platform);
 
   MSG_function_register("node", node);
   for(int i = 0 ; i< 9; i++) {
@@ -252,17 +258,16 @@ int main(int argc, char *argv[])
     xbt_free(hostname);
   }
 
-  xbt_os_cputimer_start(timer);
   msg_error_t res = MSG_main();
-  xbt_os_cputimer_stop(timer);
-  XBT_CRITICAL("Simulated time: %g", MSG_get_clock());
+  XBT_INFO("Simulated time: %g", MSG_get_clock());
 
   return res != MSG_OK;
 }
 
 static void create_jobs(xbt_matrix_t A, xbt_matrix_t B, node_job_t *jobs)
 {
-  int row = 0, col = 0;
+  int row = 0;
+  int col = 0;
 
   for (int node = 0; node < GRID_NUM_NODES; node++){
     XBT_VERB("Create job %d", node);
@@ -270,16 +275,17 @@ static void create_jobs(xbt_matrix_t A, xbt_matrix_t B, node_job_t *jobs)
     jobs[node]->row = row;
     jobs[node]->col = col;
 
-    /* Compute who are the nodes in the same row and column */
-    /* than the node receiving this job */
-    for (int j = 0, k = 0; j < GRID_SIZE; j++) {
+    /* Compute who are the nodes in the same row and column than the node receiving this job */
+    int k=0;
+    for (int j = 0; j < GRID_SIZE; j++) {
       if (node != (GRID_SIZE * row) + j) {
         jobs[node]->nodes_in_row[k] = (GRID_SIZE * row) + j;
         k++;
       }
     }
 
-    for (int j = 0, k = 0; j < GRID_SIZE; j++) {
+    k=0;
+    for (int j = 0; j < GRID_SIZE; j++) {
       if (node != (GRID_SIZE * j) + col) {
         jobs[node]->nodes_in_col[k] = (GRID_SIZE * j) + col;
         k++;
@@ -292,7 +298,8 @@ static void create_jobs(xbt_matrix_t A, xbt_matrix_t B, node_job_t *jobs)
     jobs[node]->B =
       xbt_matrix_new_sub(B, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE * row, NODE_MATRIX_SIZE * col, NULL);
 
-    if (++col >= GRID_SIZE){
+    col++;
+    if (col >= GRID_SIZE){
       col = 0;
       row++;
     }