6 #if CMK_TIMER_SIM_USE_TIMES
8 #include <sys/unistd.h>
10 #if CMK_TIMER_SIM_USE_GETRUSAGE
12 #include <sys/resource.h>
17 void CthInit(char **);
19 void ConverseCommonInit(char **);
21 void ConverseCommonExit(void);
23 static void **McQueue;
29 CsvDeclare(int, CsdStopCount);
30 CpvDeclare(void*, CmiLocalQueue);
31 CpvExtern(int, CcdNumChecks);
32 CpvExtern(int, disable_sys_msgs);
34 double CmiTimer(void);
36 static void CsiTimerInit(void);
37 static double CsiTimer(void);
40 void CmiDeliversInit(void)
45 int CsdScheduler(int maxmsgs)
47 CmiError("Cannot call scheduling functions in SIM versions.\n");
51 int CmiDeliverMsgs(int maxmsgs)
53 CmiError("Cannot call scheduling functions in SIM versions.\n");
57 void CmiDeliverSpecificMsg(int handler)
59 CmiError("Cannot call scheduling functions in SIM versions.\n");
63 CmiUniContextSwitch(int i)
68 void CmiNotifyIdle(void)
70 #if CMK_WHEN_PROCESSOR_IDLE_USLEEP
72 tv.tv_sec=0; tv.tv_usec=5000;
77 static void CmiNotifyIdleCcd(void *ignored1, double ignored2)
82 /***********************************************************************
86 ************************************************************************/
88 void CmiAbort(const char *message)
92 CMI_NORETURN_FUNCTION_END
95 void ConverseExit(int exitcode)
100 /********************* MESSAGE SEND FUNCTIONS ******************/
102 void CmiSyncSendFn(int destPE, int size, char *msg)
106 buf = (char *) CmiAlloc(size);
107 memcpy(buf,msg,size);
108 sim_send_message(_Cmi_mype,buf,size,FALSE,destPE);
114 CmiCommHandle CmiAsyncSendFn(int destPE, int size, char *msg)
116 CmiSyncSendFn(destPE, size, msg);
122 void CmiFreeSendFn(int destPE, int size, char *msg)
124 sim_send_message(_Cmi_mype,msg,size,FALSE,destPE);
129 int CmiAsyncMsgSent(CmiCommHandle c)
135 void CmiReleaseCommHandle(CmiCommHandle c)
140 void CmiNodeBarrier(void)
144 void CmiNodeAllBarrier(void)
148 /********************* MESSAGE RECEIVE FUNCTIONS ******************/
150 void *CmiGetNonLocal(void){return NULL;}
155 /*********************** BROADCAST FUNCTIONS **********************/
158 void CmiFreeBroadcastAllFn(int size, char *msg)
161 for(i=0; i<_Cmi_numpes; i++)
162 if (i!= _Cmi_mype) CmiSyncSendFn(i,size,msg);
164 CdsFifo_Enqueue(CpvAccess(CmiLocalQueue),msg);
168 void CmiSyncBroadcastFn(int size, char *msg) /* ALL_EXCEPT_ME */
171 for(i=0; i<_Cmi_numpes; i++)
172 if (i!= _Cmi_mype) CmiSyncSendFn(i,size,msg);
176 void CmiSyncBroadcastAllFn(int size, char *msg)
182 for(i=0; i<_Cmi_numpes; i++)
183 if (i!= _Cmi_mype) CmiSyncSendFn(i,size,msg);
185 buf = (char *) CmiAlloc(size);
186 memcpy(buf,msg,size);
187 CdsFifo_Enqueue(CpvAccess(CmiLocalQueue),buf);
192 void CmiFreeBroadcastFn(int size, char *msg) /* ALL_EXCEPT_ME */
194 CmiSyncBroadcastFn(size, msg);
202 CmiCommHandle CmiAsyncBroadcastFn(int size, char *msg) /* ALL_EXCEPT_ME */
204 CmiSyncBroadcastFn(size, msg);
211 CmiCommHandle CmiAsyncBroadcastAllFn(int size, char *msg)
213 CmiSyncBroadcastAll(size,msg);
218 /************************** SETUP ***********************************/
220 void ConverseInit(int argc, char **argv, CmiStartFn fn, int usc, int initret)
223 int i, requested_npe;
225 if ((usc)||(initret)) {
226 fprintf(stderr,"ConverseInit in SIM version is limited:\n");
227 fprintf(stderr," 1. User-Calls-Scheduler mode is not supported.\n");
228 fprintf(stderr," 2. ConverseInit-Returns mode is not supported.\n");
233 /* figure out number of processors required */
235 i = 0; requested_npe = 0;
236 CmiGetArgInt(argv,"+p",&requested_npe);
237 if (requested_npe <= 0) {
238 printf("Error: requested number of processors is invalid %d\n",
243 _Cmi_numpes = requested_npe;
246 McQueue = (void **) malloc(requested_npe * sizeof(void *));
247 for(i=0; i<requested_npe; i++) McQueue[i] = CdsFifo_Create();
249 sim_initialize("sim.param",requested_npe);
252 for(i=0; i<CmiNumPes(); i++) {
253 CmiUniContextSwitch(i);
254 CpvInitialize(void*, CmiLocalQueue);
255 CpvAccess(CmiLocalQueue) = CdsFifo_Create();
257 ConverseCommonInit(argv);
258 CcdCallOnConditionKeep(CcdPROCESSOR_STILL_IDLE, CmiNotifyIdleCcd, NULL);
259 argc=CmiGetArgc(argv);
260 fn(argc, CmiCopyArgs(argv));
261 CpvAccess(CsdStopFlag) = 0;
264 CsvAccess(CsdStopCount) = CmiNumPes();
265 CmiUniContextSwitch(0);
267 while (CsvAccess(CsdStopCount)) simulate();
272 /* ********************************************************************* */
274 /* ********************************************************************* */
278 #if CMK_TIMER_SIM_USE_TIMES
280 static struct tms inittime;
282 static void CsiTimerInit(void)
287 static double CsiTimer(void)
294 clk_tck=sysconf(_SC_CLK_TCK);
296 (((temp.tms_utime - inittime.tms_utime)+
297 (temp.tms_stime - inittime.tms_stime))*1.0)/clk_tck;
298 return (currenttime);
303 #if CMK_TIMER_SIM_USE_GETRUSAGE
305 static struct rusage inittime;
307 static void CsiTimerInit(void)
309 getrusage(0, &inittime);
313 static double CsiTimer(void) {
319 (temp.ru_utime.tv_usec - inittime.ru_utime.tv_usec) * 0.000001+
320 (temp.ru_utime.tv_sec - inittime.ru_utime.tv_sec) +
321 (temp.ru_stime.tv_usec - inittime.ru_stime.tv_usec) * 0.000001+
322 (temp.ru_stime.tv_sec - inittime.ru_stime.tv_sec) ;
324 return (currenttime);
331 static double Csi_global_time;
332 static double Csi_start_time;
334 void CmiTimerInit(char **argv) { }
336 double CmiTimer(void)
338 return (CsiTimer() - Csi_start_time + Csi_global_time);
341 double CmiWallTimer(void)
343 return (CsiTimer() - Csi_start_time + Csi_global_time);
346 double CmiCpuTimer(void)
348 return (CsiTimer() - Csi_start_time + Csi_global_time);
351 CmiNodeLock CmiCreateLock(void)
353 CmiNodeLock lk = (CmiNodeLock)malloc(sizeof(int));
358 void CmiLock(CmiNodeLock lk)
360 while (*lk) CmiGetNonLocal();
364 void CmiUnlock(CmiNodeLock lk)
367 CmiError("CmiNodeLock not locked, can't unlock.");
373 int CmiTryLock(CmiNodeLock lk)
375 if (*lk==0) { *lk=1; return 0; }
379 void CmiDestroyLock(CmiNodeLock lk)
384 #include "ext_func.h"