~ubuntu-branches/ubuntu/raring/simgrid/raring

« back to all changes in this revision

Viewing changes to examples/msg/io/file.c

  • Committer: Package Import Robot
  • Author(s): Lucas Nussbaum
  • Date: 2012-05-24 16:08:59 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120524160859-vhdlh05p313l5662
Tags: 3.7-1
* New upstream release.
* Bump Standards-Version to 3.9.3. No changes needed.
* debian/rules: Enable the SMPI library in the package. Closes: #656102.
* Build with -O2 on ia64. Closes: #640538.
* Use dpkg-buildflags to generate CFLAGS and LDFLAGS. Enable hardening.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
 
2
 * All rights reserved.                                                     */
 
3
 
 
4
/* This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the license (GNU LGPL) which comes with this package. */
 
6
 
 
7
/** @addtogroup MSG_examples
 
8
 * 
 
9
 * @subsection MSG_ex_resources Other resource kinds
 
10
 * 
 
11
 * This section contains some sparse examples of how to use the other
 
12
 * kind of resources, such as disk or GPU. These resources are quite
 
13
 * experimental for now, but here we go anyway.
 
14
 * 
 
15
 * - <b>io/file.c</b> Example with the disk resource
 
16
 */
 
17
 
 
18
#define FILENAME1 "/home/user/Install/simgrid/doc/simgrid/examples/platforms/g5k.xml"
 
19
#define FILENAME2 "/home/user/Install/simgrid/doc/simgrid/examples/platforms/One_cluster_no_backbone.xml"
 
20
#define FILENAME3 "/home/user/Install/simgrid/doc/simgrid/examples/platforms/g5k_cabinets.xml"
 
21
#define FILENAME4 "/home/user/Install/simgrid/doc/simgrid/examples/platforms/nancy.xml"
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include "msg/msg.h"
 
26
#include "surf/surf_private.h"
 
27
 
 
28
int host(int argc, char *argv[]);
 
29
 
 
30
XBT_LOG_NEW_DEFAULT_CATEGORY(io_file,
 
31
                             "Messages specific for this io example");
 
32
 
 
33
int host(int argc, char *argv[])
 
34
{
 
35
  msg_file_t file = NULL;
 
36
  s_msg_stat_t stat;
 
37
 
 
38
  char* mount = bprintf("C:");
 
39
  size_t read,write;
 
40
  if(!strcmp(MSG_process_get_name(MSG_process_self()),"0"))
 
41
    file = MSG_file_open(mount,FILENAME1,"rw");
 
42
  else if(!strcmp(MSG_process_get_name(MSG_process_self()),"1"))
 
43
    file = MSG_file_open(mount,FILENAME2,"rw");
 
44
  else if(!strcmp(MSG_process_get_name(MSG_process_self()),"2"))
 
45
    file = MSG_file_open(mount,FILENAME3,"rw");
 
46
  else if(!strcmp(MSG_process_get_name(MSG_process_self()),"3"))
 
47
    file = MSG_file_open(mount,FILENAME4,"rw");
 
48
  else xbt_die("FILENAME NOT DEFINED %s",MSG_process_get_name(MSG_process_self()));
 
49
 
 
50
  XBT_INFO("\tOpen file '%s'",file->name);
 
51
 
 
52
  read = MSG_file_read(mount,NULL,10000000,sizeof(char*),file);     // Read for 10Mo
 
53
  XBT_INFO("\tHaving read  %Zu \ton %s",read,file->name);
 
54
 
 
55
  write = MSG_file_write(mount,NULL,100000,sizeof(char*),file);  // Write for 100Ko
 
56
  XBT_INFO("\tHaving write %Zu \ton %s",write,file->name);
 
57
 
 
58
  read = MSG_file_read(mount,NULL,10000000,sizeof(char*),file);     // Read for 10Mo
 
59
  XBT_INFO("\tHaving read  %Zu \ton %s",read,file->name);
 
60
 
 
61
  MSG_file_stat(mount,file,&stat);
 
62
  XBT_INFO("\tFile %s Size %d",file->name,(int)stat.size);
 
63
 
 
64
  XBT_INFO("\tClose file '%s'",file->name);
 
65
  MSG_file_close(mount,file);
 
66
 
 
67
  free(mount);
 
68
  return 0;
 
69
}
 
70
 
 
71
int main(int argc, char **argv)
 
72
{
 
73
    int i,res;
 
74
  MSG_global_init(&argc, argv);
 
75
  MSG_create_environment(argv[1]);
 
76
  xbt_dynar_t hosts =  MSG_hosts_as_dynar();
 
77
  MSG_function_register("host", host);
 
78
 
 
79
  XBT_INFO("Number of host '%lu'",xbt_dynar_length(hosts));
 
80
  for(i = 0 ; i<xbt_dynar_length(hosts); i++)
 
81
  {
 
82
    char* name_host = bprintf("%d",i);
 
83
    MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,m_host_t) );
 
84
    free(name_host);
 
85
  }
 
86
  xbt_dynar_free(&hosts);
 
87
 
 
88
  res = MSG_main();
 
89
  XBT_INFO("Simulation time %g", MSG_get_clock());
 
90
  MSG_clean();
 
91
  if (res == MSG_OK)
 
92
    return 0;
 
93
  else
 
94
    return 1;
 
95
 
 
96
}