cf4c8583f2537bbd4b8011a66592a2685f9192d7
[charm.git] / src / ck-perf / tracef.C
1 /****************************************************************************
2              Fortran API for common Trace functions
3 ****************************************************************************/
4
5 #include<charm++.h>
6 #include<charm-api.h>
7                                                                                 
8 CpvStaticDeclare(int, a);
9                                                                                 
10 static int isInitialized=0;
11                                                                                 
12 static void checkInit(void) {
13         if (isInitialized) return;
14         isInitialized=1;
15         CpvInitialize(int,a);
16         CpvAccess(a)=0;
17 }
18
19 FDECL {
20
21 #define ftracebegin              FTN_NAME(FTRACEBEGIN, ftracebegin)
22 #define ftraceend                FTN_NAME(FTRACEEND, ftraceend)
23 #define ftraceregisteruserevent  FTN_NAME(FTRACEREGISTERUSEREVENT, ftraceregisteruserevent)
24 #define ftraceuserbracketevent   FTN_NAME(FTRACEUSERBRACKETEVENT, ftraceuserbracketevent)
25
26 void ftracebegin()
27 {
28           checkInit();
29           if ( CpvAccess(a) ==0)
30                 {
31                         traceBegin();
32                         CpvAccess(a)++;
33                 }
34           else
35                 { CpvAccess(a)++;}
36 }
37
38 void FTN_NAME(FTRACEEND, ftraceend)()
39 {
40           checkInit();
41           if ( CpvAccess(a) == 1)
42                 {
43                         traceEnd();
44                         CpvAccess(a)--;
45                 }
46           else
47                 { CpvAccess(a)--;}
48                                                                                 
49 }
50
51 void ftraceregisteruserevent(char *x, int *ein, int *eout, int len)
52 {
53   char *newstr = new char[len + 1];
54   _MEMCHECK(newstr);
55   strncpy(newstr, x, len);
56   newstr[len] = 0;
57   int newe = traceRegisterUserEvent(newstr, *ein);
58   *eout = newe;
59 }
60
61 void ftraceuserbracketevent(int *e, double *begint, double *endt)
62 {
63   traceUserBracketEvent(*e, *begint, *endt);
64 }
65
66 }  // FDECL
67