Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow this example to start without paramters
[simgrid.git] / examples / msg / app-pmm / app-pmm.c
index f55f1a2..dd5e22a 100644 (file)
@@ -1,7 +1,6 @@
-/* pmm - parallel matrix multiplication "double diffusion"                  */
+/* pmm - double broadcast parallel matrix multiplication                    */
 
-/* Copyright (c) 2006-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2006-2016. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -10,13 +9,6 @@
 #include "xbt/matrix.h"
 #include "xbt/xbt_os_time.h"
 
-/** @addtogroup MSG_examples
- *  @section msg_ex_full_apps Examples of full applications
- *
- * - <b>Parallel Matrix Multiplication: app-pmm/app-pmm.c</b>. This little application is something that most MPI
- *   developers have written during their studies. Here it is implemented in MSG.
- */
-
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_pmm, "Messages specific for this msg example");
 
 /* This example should always be executed using a deployment of GRID_SIZE * GRID_SIZE nodes. */
@@ -62,7 +54,9 @@ 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;
+  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");
@@ -70,9 +64,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);
@@ -88,13 +82,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);
@@ -247,7 +243,10 @@ 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++) {
@@ -263,14 +262,15 @@ int main(int argc, char *argv[])
   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);