Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Last bits of convertion from xbt_error_t to exceptions. Some more cleanups (mainly...
[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   double rate;
40   int using;
41   /*******  Parallel Tasks Only !!!! *******/
42   int host_nb;
43   void * *host_list;            /* SURF modeling */
44   double *comp_amount;
45   double *comm_amount;
46 } s_simdata_task_t;
47
48 /******************************* Process *************************************/
49
50 typedef struct simdata_process {
51   m_host_t host;                /* the host on which the process is running */
52   xbt_context_t context;                /* the context that executes the scheduler fonction */
53   int PID;                      /* used for debugging purposes */
54   int PPID;                     /* The parent PID */
55   m_task_t waiting_task;        
56   int blocked;
57   int suspended;
58   m_host_t put_host;            /* used for debugging purposes */
59   m_channel_t put_channel;      /* used for debugging purposes */
60   int argc;                     /* arguments number if any */
61   char **argv;                  /* arguments table if any */
62   MSG_error_t last_errno;       /* the last value returned by a MSG_function */
63   int paje_state;               /* the number of states stacked with Paje */
64 } s_simdata_process_t;
65
66 typedef struct process_arg {
67   const char *name;
68   m_process_code_t code;
69   void *data;
70   m_host_t host;
71   int argc;
72   char **argv;
73   double kill_time;
74 } s_process_arg_t, *process_arg_t;
75
76 /************************** Global variables ********************************/
77 typedef struct MSG_Global {
78   xbt_fifo_t host;
79   xbt_fifo_t process_to_run;
80   xbt_fifo_t process_list;
81   int max_channel;
82   m_process_t current_process;
83   xbt_dict_t registered_functions;
84   FILE *paje_output;
85   int paje_maxPID;
86   int PID;
87   int session;
88 } s_MSG_Global_t, *MSG_Global_t;
89
90 extern MSG_Global_t msg_global;
91       
92 /************************** Configuration support ********************************/
93 void msg_config_init(void); /* create the config set, call this before use! */
94 extern int _msg_init_status; /* 0: beginning of time; 
95                                 1: pre-inited (cfg_set created); 
96                                 2: inited (running) */
97 extern xbt_cfg_t _msg_cfg_set;
98
99 /*************************************************************/
100
101 #define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val)
102 #define PROCESS_GET_ERRNO() (MSG_process_self()->simdata->last_errno)
103 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
104 /* #define CHECK_ERRNO()  ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
105
106 #define CHECK_HOST()  xbt_assert0(surf_workstation_resource->extension_public-> \
107                                   get_state(MSG_host_self()->simdata->host)==SURF_CPU_ON,\
108                                   "Host failed, you cannot call this function.")
109
110 m_host_t __MSG_host_create(const char *name, void *workstation,
111                            void *data);
112 void __MSG_host_destroy(m_host_t host);
113 void __MSG_task_execute(m_process_t process, m_task_t task);
114 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task);
115 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task);
116
117 int __MSG_process_block(double max_duration);
118 MSG_error_t __MSG_process_unblock(m_process_t process);
119 int __MSG_process_isBlocked(m_process_t process);
120
121 #ifdef ALVIN_SPECIAL_LOGING
122 #define PAJE_PROCESS_STATE(process,state)\
123   if(msg_global->paje_output) \
124     fprintf(msg_global->paje_output,"10 %g S_t P%d %s\n",\
125             surf_get_clock(), (process)->simdata->PID,(state))
126 #define PAJE_PROCESS_PUSH_STATE(process,state)\
127   if(msg_global->paje_output) { \
128     fprintf(msg_global->paje_output,"11 %g S_t P%d %s\n",\
129             surf_get_clock(), (process)->simdata->PID,(state));\
130     (process)->simdata->paje_state++; \
131   }
132 #define PAJE_PROCESS_POP_STATE(process)\
133   if(msg_global->paje_output) { \
134     fprintf(msg_global->paje_output,"12 %g S_t P%d\n",\
135             surf_get_clock(), (process)->simdata->PID); \
136     (process)->simdata->paje_state--; \
137   }
138 #define PAJE_PROCESS_FREE(process)
139 #define PAJE_PROCESS_NEW(process)\
140   if((msg_global->paje_output)) {\
141     if((msg_global->session==0) || ((msg_global->session>0) && ((process)->simdata->PID > msg_global->paje_maxPID))) \
142     fprintf(msg_global->paje_output,"7 %g P%d P_t %p \"%s %d (%d)\"\n", \
143             surf_get_clock(), (process)->simdata->PID, (process)->simdata->host, \
144             (process)->name, (process)->simdata->PID, msg_global->session);\
145     if(msg_global->paje_maxPID<(process)->simdata->PID) msg_global->paje_maxPID=(process)->simdata->PID;\
146     }
147 #define PAJE_COMM_START(process,task,channel)\
148   if(msg_global->paje_output) \
149     fprintf(msg_global->paje_output,\
150             "16 %g      Comm    CUR     COMM_%d P%d     %p\n", \
151             surf_get_clock(), channel, (process)->simdata->PID, task)
152 #define PAJE_COMM_STOP(process,task,channel)\
153   if(msg_global->paje_output) \
154     fprintf(msg_global->paje_output,\
155             "17 %g      Comm    CUR     COMM_%d P%d     %p\n", \
156             surf_get_clock(), channel, (process)->simdata->PID, task)
157 #define PAJE_HOST_NEW(host)\
158   if(msg_global->paje_output)\
159     fprintf(msg_global->paje_output,"7 %g %p H_t CUR \"%s\"\n",surf_get_clock(), \
160             host, host->name)
161 #define PAJE_HOST_FREE(host)\
162   if(msg_global->paje_output)\
163     fprintf(msg_global->paje_output,"8 %g %p H_t\n",surf_get_clock(), host)
164
165 #else
166
167 #define PAJE_PROCESS_STATE(process,state)\
168   if(msg_global->paje_output) \
169     fprintf(msg_global->paje_output,"10 %g S_t %p %s\n",\
170             surf_get_clock(), (process),(state))
171 #define PAJE_PROCESS_PUSH_STATE(process,state)\
172   if(msg_global->paje_output) \
173     fprintf(msg_global->paje_output,"11 %g S_t %p %s\n",\
174             surf_get_clock(), (process),(state))
175 #define PAJE_PROCESS_POP_STATE(process)\
176   if(msg_global->paje_output) \
177     fprintf(msg_global->paje_output,"12 %g S_t %p\n",\
178             surf_get_clock(), (process))
179
180 #define PAJE_PROCESS_FREE(process)\
181   if(msg_global->paje_output) \
182     fprintf(msg_global->paje_output,"8 %g %p P_t\n", \
183             surf_get_clock(), (process))
184 #define PAJE_PROCESS_NEW(process)\
185   if(msg_global->paje_output) \
186     fprintf(msg_global->paje_output,"7 %g %p P_t %p \"%s %d (%d)\"\n", \
187             surf_get_clock(), (process), (process)->simdata->host, \
188             (process)->name, (process)->simdata->PID, msg_global->session)
189 #define PAJE_COMM_START(process,task,channel)\
190   if(msg_global->paje_output) \
191     fprintf(msg_global->paje_output,\
192             "16 %g      Comm    CUR     COMM_%d %p      %p\n", \
193             surf_get_clock(), channel, (process), task)
194 #define PAJE_COMM_STOP(process,task,channel)\
195   if(msg_global->paje_output) \
196     fprintf(msg_global->paje_output,\
197             "17 %g      Comm    CUR     COMM_%d %p      %p\n", \
198             surf_get_clock(), channel, (process), task)
199 #define PAJE_HOST_NEW(host)\
200   if(msg_global->paje_output)\
201     fprintf(msg_global->paje_output,"7 %g %p H_t CUR \"%s\"\n",surf_get_clock(), \
202             host, host->name)
203 #define PAJE_HOST_FREE(host)\
204   if(msg_global->paje_output)\
205     fprintf(msg_global->paje_output,"8 %g %p H_t\n",surf_get_clock(), host);
206
207 #endif /* Alvin_Special_Loging */
208 #endif