Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
moved to %f instead of %g. It's usefull when values get large...
[simgrid.git] / src / msg / private.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2004,2004 Arnaud Legrand. All rights reserved.        */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef METASIMGRID_PRIVATE_H
9 #define METASIMGRID_PRIVATE_H
10
11 #include "msg/msg.h"
12 #include "surf/surf.h"
13 #include "xbt/fifo.h"
14 #include "xbt/dynar.h"
15 #include "xbt/swag.h"
16 #include "xbt/dict.h"
17 #include "xbt/context.h"
18 #include "xbt/config.h"
19
20 /**************** datatypes **********************************/
21
22 typedef struct simdata_host {
23   void *host;                   /* SURF modeling */
24   xbt_fifo_t *mbox;             /* array of FIFOs used as a mailboxes  */
25   m_process_t *sleeping;        /* array of process used to know whether a local process is
26                                    waiting for a communication on a channel */
27   xbt_fifo_t process_list;
28 } s_simdata_host_t;
29
30 /********************************* Task **************************************/
31
32 typedef struct simdata_task {
33   surf_action_t compute;        /* SURF modeling of computation  */
34   surf_action_t comm;           /* SURF modeling of communication  */
35   double message_size;          /* Data size  */
36   double computation_amount;    /* Computation size  */
37   xbt_dynar_t sleeping;         /* process to wake-up */
38   m_process_t sender;
39   m_host_t source;
40   double priority;
41   double rate;
42   int using;
43   /*******  Parallel Tasks Only !!!! *******/
44   int host_nb;
45   void * *host_list;            /* SURF modeling */
46   double *comp_amount;
47   double *comm_amount;
48 } s_simdata_task_t;
49
50 /******************************* Process *************************************/
51
52 typedef struct simdata_process {
53   m_host_t host;                /* the host on which the process is running */
54   xbt_context_t context;                /* the context that executes the scheduler fonction */
55   int PID;                      /* used for debugging purposes */
56   int PPID;                     /* The parent PID */
57   m_task_t waiting_task;        
58   int blocked;
59   int suspended;
60   m_host_t put_host;            /* used for debugging purposes */
61   m_channel_t put_channel;      /* used for debugging purposes */
62   int argc;                     /* arguments number if any */
63   char **argv;                  /* arguments table if any */
64   MSG_error_t last_errno;       /* the last value returned by a MSG_function */
65   int paje_state;               /* the number of states stacked with Paje */
66 } s_simdata_process_t;
67
68 typedef struct process_arg {
69   const char *name;
70   m_process_code_t code;
71   void *data;
72   m_host_t host;
73   int argc;
74   char **argv;
75   double kill_time;
76 } s_process_arg_t, *process_arg_t;
77
78 /************************** Global variables ********************************/
79 typedef struct MSG_Global {
80   xbt_fifo_t host;
81   xbt_fifo_t process_to_run;
82   xbt_fifo_t process_list;
83   int max_channel;
84   m_process_t current_process;
85   xbt_dict_t registered_functions;
86   FILE *paje_output;
87   int paje_maxPID;
88   int PID;
89   int session;
90 } s_MSG_Global_t, *MSG_Global_t;
91
92 extern MSG_Global_t msg_global;
93       
94 /************************** Configuration support ********************************/
95 void msg_config_init(void); /* create the config set, call this before use! */
96 void msg_config_finalize(void); /* destroy the config set, call this at cleanup. */
97 extern int _msg_init_status; /* 0: beginning of time; 
98                                 1: pre-inited (cfg_set created); 
99                                 2: inited (running) */
100 extern xbt_cfg_t _msg_cfg_set;
101
102 /*************************************************************/
103
104 #define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val)
105 #define PROCESS_GET_ERRNO() (MSG_process_self()->simdata->last_errno)
106 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
107 /* #define CHECK_ERRNO()  ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
108
109 #define CHECK_HOST()  xbt_assert0(surf_workstation_resource->extension_public-> \
110                                   get_state(MSG_host_self()->simdata->host)==SURF_CPU_ON,\
111                                   "Host failed, you cannot call this function.")
112
113 m_host_t __MSG_host_create(const char *name, void *workstation,
114                            void *data);
115 void __MSG_host_destroy(m_host_t host);
116 void __MSG_task_execute(m_process_t process, m_task_t task);
117 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task);
118 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task);
119
120 int __MSG_process_block(double max_duration);
121 MSG_error_t __MSG_process_unblock(m_process_t process);
122 int __MSG_process_isBlocked(m_process_t process);
123
124 #ifdef ALVIN_SPECIAL_LOGING
125 #define PAJE_PROCESS_STATE(process,state)\
126   if(msg_global->paje_output) \
127     fprintf(msg_global->paje_output,"10 %f S_t P%d %s\n",\
128             surf_get_clock(), (process)->simdata->PID,(state))
129 #define PAJE_PROCESS_PUSH_STATE(process,state)\
130   if(msg_global->paje_output) { \
131     fprintf(msg_global->paje_output,"11 %f S_t P%d %s\n",\
132             surf_get_clock(), (process)->simdata->PID,(state));\
133     (process)->simdata->paje_state++; \
134   }
135 #define PAJE_PROCESS_POP_STATE(process)\
136   if(msg_global->paje_output) { \
137     fprintf(msg_global->paje_output,"12 %f S_t P%d\n",\
138             surf_get_clock(), (process)->simdata->PID); \
139     (process)->simdata->paje_state--; \
140   }
141 #define PAJE_PROCESS_FREE(process)
142 #define PAJE_PROCESS_NEW(process)\
143   if((msg_global->paje_output)) {\
144     if((msg_global->session==0) || ((msg_global->session>0) && ((process)->simdata->PID > msg_global->paje_maxPID))) \
145     fprintf(msg_global->paje_output,"7 %f P%d P_t %p \"%s %d (%d)\"\n", \
146             surf_get_clock(), (process)->simdata->PID, (process)->simdata->host, \
147             (process)->name, (process)->simdata->PID, msg_global->session);\
148     if(msg_global->paje_maxPID<(process)->simdata->PID) msg_global->paje_maxPID=(process)->simdata->PID;\
149     }
150 #define PAJE_COMM_START(process,task,channel)\
151   if(msg_global->paje_output) \
152     fprintf(msg_global->paje_output,\
153             "16 %f      Comm    CUR     COMM_%d P%d     %p\n", \
154             surf_get_clock(), channel, (process)->simdata->PID, task)
155 #define PAJE_COMM_STOP(process,task,channel)\
156   if(msg_global->paje_output) \
157     fprintf(msg_global->paje_output,\
158             "17 %f      Comm    CUR     COMM_%d P%d     %p\n", \
159             surf_get_clock(), channel, (process)->simdata->PID, task)
160 #define PAJE_HOST_NEW(host)\
161   if(msg_global->paje_output)\
162     fprintf(msg_global->paje_output,"7 %f %p H_t CUR \"%s\"\n",surf_get_clock(), \
163             host, host->name)
164 #define PAJE_HOST_FREE(host)\
165   if(msg_global->paje_output)\
166     fprintf(msg_global->paje_output,"8 %f %p H_t\n",surf_get_clock(), host)
167
168 #else
169
170 #define PAJE_PROCESS_STATE(process,state)\
171   if(msg_global->paje_output) \
172     fprintf(msg_global->paje_output,"10 %f S_t %p %s\n",\
173             surf_get_clock(), (process),(state))
174 #define PAJE_PROCESS_PUSH_STATE(process,state)\
175   if(msg_global->paje_output) \
176     fprintf(msg_global->paje_output,"11 %f S_t %p %s\n",\
177             surf_get_clock(), (process),(state))
178 #define PAJE_PROCESS_POP_STATE(process)\
179   if(msg_global->paje_output) \
180     fprintf(msg_global->paje_output,"12 %f S_t %p\n",\
181             surf_get_clock(), (process))
182
183 #define PAJE_PROCESS_FREE(process)\
184   if(msg_global->paje_output) \
185     fprintf(msg_global->paje_output,"8 %f %p P_t\n", \
186             surf_get_clock(), (process))
187 #define PAJE_PROCESS_NEW(process)\
188   if(msg_global->paje_output) \
189     fprintf(msg_global->paje_output,"7 %f %p P_t %p \"%s %d (%d)\"\n", \
190             surf_get_clock(), (process), (process)->simdata->host, \
191             (process)->name, (process)->simdata->PID, msg_global->session)
192 #define PAJE_COMM_START(process,task,channel)\
193   if(msg_global->paje_output) \
194     fprintf(msg_global->paje_output,\
195             "16 %f      Comm    CUR     COMM_%d %p      %p\n", \
196             surf_get_clock(), channel, (process), task)
197 #define PAJE_COMM_STOP(process,task,channel)\
198   if(msg_global->paje_output) \
199     fprintf(msg_global->paje_output,\
200             "17 %f      Comm    CUR     COMM_%d %p      %p\n", \
201             surf_get_clock(), channel, (process), task)
202 #define PAJE_HOST_NEW(host)\
203   if(msg_global->paje_output)\
204     fprintf(msg_global->paje_output,"7 %f %p H_t CUR \"%s\"\n",surf_get_clock(), \
205             host, host->name)
206 #define PAJE_HOST_FREE(host)\
207   if(msg_global->paje_output)\
208     fprintf(msg_global->paje_output,"8 %f %p H_t\n",surf_get_clock(), host);
209
210 #endif /* Alvin_Special_Loging */
211 #endif