build: fix travis MPI/SMP build
[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 static char * FortrantoCString(char *x,int len){
20         char *newstr = new char[len + 1];
21   _MEMCHECK(newstr);
22   strncpy(newstr, x, len);
23   newstr[len] = 0;
24         return newstr;
25 }
26
27
28 FLINKAGE {
29
30 #define ftracebegin              FTN_NAME(FTRACEBEGIN, ftracebegin)
31 #define ftraceend                FTN_NAME(FTRACEEND, ftraceend)
32 #define ftraceregisteruserevent  FTN_NAME(FTRACEREGISTERUSEREVENT, ftraceregisteruserevent)
33 #define ftraceuserbracketevent   FTN_NAME(FTRACEUSERBRACKETEVENT, ftraceuserbracketevent)
34 #define ftraceUserEvent          FTN_NAME(FTRACEUSEREVENT, ftraceuserevent)
35 #define ftraceFlushLog           FTN_NAME(FTRACEFLUSHLOG, ftraceflushlog)
36
37 #define fbgprintf                FTN_NAME(FBGPRINTF, fbgprintf)
38
39 void ftracebegin()
40 {
41           checkInit();
42           if ( CpvAccess(a) ==0)
43                 {
44                         traceBegin();
45                         CpvAccess(a)++;
46                 }
47           else
48                 { CpvAccess(a)++;}
49 }
50
51 void ftraceend()
52 {
53           checkInit();
54           if ( CpvAccess(a) == 1)
55                 {
56                         traceEnd();
57                         CpvAccess(a)--;
58                 }
59           else
60                 { CpvAccess(a)--;}
61                                                                                 
62 }
63
64 void ftraceregisteruserevent(char *x, int *ein, int *eout, int len)
65 {
66   char *newstr = new char[len + 1];
67   _MEMCHECK(newstr);
68   strncpy(newstr, x, len);
69   newstr[len] = 0;
70   int newe = traceRegisterUserEvent(newstr, *ein);
71   *eout = newe;
72 }
73
74 void ftraceuserbracketevent(int *e, double *begint, double *endt)
75 {
76   traceUserBracketEvent(*e, *begint, *endt);
77 }
78
79 void ftraceUserEvent(int *e)
80 {
81   traceUserEvent(*e);
82 }
83
84 void ftraceFlushLog()
85 {
86   traceFlushLog();
87 }
88
89 #if CMK_BIGSIM_CHARM
90 void fbgprintf(char *str, int len)
91 {
92   char *newstr = new char[len + 1];
93   _MEMCHECK(newstr);
94   strncpy(newstr, str, len);
95   newstr[len] = 0;
96   BgPrintf(newstr);
97   delete [] newstr;
98 }
99 #endif
100
101 }  // FLINKAGE
102