Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify this example
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 1 Jun 2016 10:19:56 +0000 (12:19 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 1 Jun 2016 10:19:56 +0000 (12:19 +0200)
examples/msg/io-file/io-file.c
examples/msg/io-file/io-file.tesh

index f5fdb14..0e91b06 100644 (file)
@@ -15,25 +15,32 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(io_file, "Messages specific for this io example");
 static int host(int argc, char *argv[])
 {
   msg_file_t file = NULL;
-  sg_size_t read,write;
+  sg_size_t read;
+  sg_size_t write;
   msg_storage_t st;
   const char* st_name;
 
-  if(!strcmp(MSG_process_get_name(MSG_process_self()),"0")){
+  switch(MSG_process_self_PID()){
+  case 1:
     file = MSG_file_open(FILENAME1, NULL);
     MSG_file_dump(file);
     st_name = "Disk4";
-  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"1")) {
+    break;
+  case 2 :
     file = MSG_file_open(FILENAME2, NULL);
     st_name = "Disk2";
-  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"2")){
+    break;
+  case 3 :
     file = MSG_file_open(FILENAME3, NULL);
     st_name = "Disk3";
-  } else if(!strcmp(MSG_process_get_name(MSG_process_self()),"3")){
+    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()));
   }
-  else 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);
@@ -73,7 +80,7 @@ static int host(int argc, char *argv[])
   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(!strcmp(MSG_process_get_name(MSG_process_self()),"0")){
+  if (MSG_process_self_PID() == 1){
     XBT_INFO("\tUnlink file '%s'",MSG_file_get_name(file));
     MSG_file_unlink(file);
   } else {
@@ -91,10 +98,8 @@ int main(int argc, char **argv)
   MSG_function_register("host", host);
   unsigned long nb_hosts = xbt_dynar_length(hosts);
   XBT_INFO("Number of host '%lu'",nb_hosts);
-  for(int i = 0 ; i<nb_hosts; i++){
-    char* name_host = bprintf("%d",i);
-    MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) );
-    free(name_host);
+  for(int i = 0 ; i < nb_hosts; i++){
+    MSG_process_create("host", host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t));
   }
   xbt_dynar_free(&hosts);
 
index 9c88ea9..0db9f49 100644 (file)
@@ -2,10 +2,10 @@
 
 $ ${bindir:=.}/io-file ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
 > [  0.000000] (0:maestro@) Number of host '4'
-> [  0.000000] (2:1@alice)     Open file 'c:\Windows\setupact.log'
-> [  0.000000] (3:2@carl)      Open file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
-> [  0.000000] (4:3@bob)       Open file '/home/doc/simgrid/examples/platforms/nancy.xml'
-> [  0.000000] (1:0@denise) File Descriptor information:
+> [  0.000000] (2:host@alice)  Open file 'c:\Windows\setupact.log'
+> [  0.000000] (3:host@carl)   Open file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
+> [  0.000000] (4:host@bob)    Open file '/home/doc/simgrid/examples/platforms/nancy.xml'
+> [  0.000000] (1:host@denise) File Descriptor information:
 >              Full path: '/home/doc/simgrid/examples/platforms/g5k.xml'
 >              Size: 17028
 >              Mount point: '/home'
@@ -13,45 +13,45 @@ $ ${bindir:=.}/io-file ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r]
 >              Storage Type: 'single_SSD'
 >              Content Type: 'txt_unix'
 >              File Descriptor Id: 0
-> [  0.000000] (1:0@denise)    Open file '/home/doc/simgrid/examples/platforms/g5k.xml'
-> [  0.000000] (2:1@alice)     Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391537133 / 536870912000
-> [  0.000000] (3:2@carl)      Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 36946053 / 536870912000
-> [  0.000000] (4:3@bob)       Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 36946053 / 536870912000
-> [  0.000000] (1:0@denise)    Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13221994 / 536870912000
-> [  0.000040] (4:3@bob)       Have read 4028 from '/home/doc/simgrid/examples/platforms/nancy.xml'
-> [  0.000085] (1:0@denise)    Have read 17028 from '/home/doc/simgrid/examples/platforms/g5k.xml'
-> [  0.000226] (3:2@carl)      Have read 22645 from '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
-> [  0.000508] (2:1@alice)     Have read 101663 from 'c:\Windows\setupact.log'
-> [  0.001752] (1:0@denise)    Have written 100000 in '/home/doc/simgrid/examples/platforms/g5k.xml'. Size now is: 117028
-> [  0.001752] (1:0@denise)    Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13321994 / 536870912000
-> [  0.001752] (1:0@denise)    Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/g5k.xml'
-> [  0.002175] (2:1@alice)     Have written 100000 in 'c:\Windows\setupact.log'. Size now is: 201663
-> [  0.002175] (2:1@alice)     Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391637133 / 536870912000
-> [  0.002175] (2:1@alice)     Coming back to the beginning of the stream for file 'c:\Windows\setupact.log'
-> [  0.002302] (1:0@denise)    Have read 110000 from '/home/doc/simgrid/examples/platforms/g5k.xml' (of size 117028)
-> [  0.002302] (1:0@denise)    Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/g5k.xml'
-> [  0.002725] (2:1@alice)     Have read 110000 from 'c:\Windows\setupact.log' (of size 201663)
-> [  0.002725] (2:1@alice)     Coming back to the beginning of the stream for file 'c:\Windows\setupact.log'
-> [  0.003374] (4:3@bob)       Have written 100000 in '/home/doc/simgrid/examples/platforms/nancy.xml'. Size now is: 104028
-> [  0.003374] (4:3@bob)       Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 37046053 / 536870912000
-> [  0.003374] (4:3@bob)       Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/nancy.xml'
-> [  0.003560] (3:2@carl)      Have written 100000 in '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'. Size now is: 122645
-> [  0.003560] (3:2@carl)      Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 37046053 / 536870912000
-> [  0.003560] (3:2@carl)      Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
-> [  0.004135] (1:0@denise)    Have written 110000 in '/home/doc/simgrid/examples/platforms/g5k.xml'. Size now is: 110000
-> [  0.004135] (1:0@denise)    Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13314966 / 536870912000
-> [  0.004135] (1:0@denise)    Unlink file '/home/doc/simgrid/examples/platforms/g5k.xml'
-> [  0.004414] (4:3@bob)       Have read 104028 from '/home/doc/simgrid/examples/platforms/nancy.xml' (of size 104028)
-> [  0.004414] (4:3@bob)       Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/nancy.xml'
-> [  0.004558] (2:1@alice)     Have written 110000 in 'c:\Windows\setupact.log'. Size now is: 110000
-> [  0.004558] (2:1@alice)     Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391545470 / 536870912000
-> [  0.004558] (2:1@alice)     Close file 'c:\Windows\setupact.log'
-> [  0.004660] (3:2@carl)      Have read 110000 from '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' (of size 122645)
-> [  0.004660] (3:2@carl)      Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
-> [  0.008081] (4:3@bob)       Have written 110000 in '/home/doc/simgrid/examples/platforms/nancy.xml'. Size now is: 110000
-> [  0.008081] (4:3@bob)       Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 37052025 / 536870912000
-> [  0.008081] (4:3@bob)       Close file '/home/doc/simgrid/examples/platforms/nancy.xml'
-> [  0.008326] (3:2@carl)      Have written 110000 in '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'. Size now is: 110000
-> [  0.008326] (3:2@carl)      Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 37033408 / 536870912000
-> [  0.008326] (3:2@carl)      Close file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
+> [  0.000000] (1:host@denise)         Open file '/home/doc/simgrid/examples/platforms/g5k.xml'
+> [  0.000000] (2:host@alice)  Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391537133 / 536870912000
+> [  0.000000] (3:host@carl)   Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 36946053 / 536870912000
+> [  0.000000] (4:host@bob)    Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 36946053 / 536870912000
+> [  0.000000] (1:host@denise)         Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13221994 / 536870912000
+> [  0.000040] (4:host@bob)    Have read 4028 from '/home/doc/simgrid/examples/platforms/nancy.xml'
+> [  0.000085] (1:host@denise)         Have read 17028 from '/home/doc/simgrid/examples/platforms/g5k.xml'
+> [  0.000226] (3:host@carl)   Have read 22645 from '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
+> [  0.000508] (2:host@alice)  Have read 101663 from 'c:\Windows\setupact.log'
+> [  0.001752] (1:host@denise)         Have written 100000 in '/home/doc/simgrid/examples/platforms/g5k.xml'. Size now is: 117028
+> [  0.001752] (1:host@denise)         Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13321994 / 536870912000
+> [  0.001752] (1:host@denise)         Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/g5k.xml'
+> [  0.002175] (2:host@alice)  Have written 100000 in 'c:\Windows\setupact.log'. Size now is: 201663
+> [  0.002175] (2:host@alice)  Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391637133 / 536870912000
+> [  0.002175] (2:host@alice)  Coming back to the beginning of the stream for file 'c:\Windows\setupact.log'
+> [  0.002302] (1:host@denise)         Have read 110000 from '/home/doc/simgrid/examples/platforms/g5k.xml' (of size 117028)
+> [  0.002302] (1:host@denise)         Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/g5k.xml'
+> [  0.002725] (2:host@alice)  Have read 110000 from 'c:\Windows\setupact.log' (of size 201663)
+> [  0.002725] (2:host@alice)  Coming back to the beginning of the stream for file 'c:\Windows\setupact.log'
+> [  0.003374] (4:host@bob)    Have written 100000 in '/home/doc/simgrid/examples/platforms/nancy.xml'. Size now is: 104028
+> [  0.003374] (4:host@bob)    Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 37046053 / 536870912000
+> [  0.003374] (4:host@bob)    Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/nancy.xml'
+> [  0.003560] (3:host@carl)   Have written 100000 in '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'. Size now is: 122645
+> [  0.003560] (3:host@carl)   Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 37046053 / 536870912000
+> [  0.003560] (3:host@carl)   Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
+> [  0.004135] (1:host@denise)         Have written 110000 in '/home/doc/simgrid/examples/platforms/g5k.xml'. Size now is: 110000
+> [  0.004135] (1:host@denise)         Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13314966 / 536870912000
+> [  0.004135] (1:host@denise)         Unlink file '/home/doc/simgrid/examples/platforms/g5k.xml'
+> [  0.004414] (4:host@bob)    Have read 104028 from '/home/doc/simgrid/examples/platforms/nancy.xml' (of size 104028)
+> [  0.004414] (4:host@bob)    Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/nancy.xml'
+> [  0.004558] (2:host@alice)  Have written 110000 in 'c:\Windows\setupact.log'. Size now is: 110000
+> [  0.004558] (2:host@alice)  Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391545470 / 536870912000
+> [  0.004558] (2:host@alice)  Close file 'c:\Windows\setupact.log'
+> [  0.004660] (3:host@carl)   Have read 110000 from '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' (of size 122645)
+> [  0.004660] (3:host@carl)   Coming back to the beginning of the stream for file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
+> [  0.008081] (4:host@bob)    Have written 110000 in '/home/doc/simgrid/examples/platforms/nancy.xml'. Size now is: 110000
+> [  0.008081] (4:host@bob)    Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 37052025 / 536870912000
+> [  0.008081] (4:host@bob)    Close file '/home/doc/simgrid/examples/platforms/nancy.xml'
+> [  0.008326] (3:host@carl)   Have written 110000 in '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'. Size now is: 110000
+> [  0.008326] (3:host@carl)   Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 37033408 / 536870912000
+> [  0.008326] (3:host@carl)   Close file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
 > [  0.008326] (0:maestro@) Simulation time 0.00832645