00001
00002
00003
00004
00005 #include "charm++.h"
00006 #include <stdarg.h>
00007 #include "charmf.h"
00008 #include "cktiming.h"
00009 #include "memory-isomalloc.h"
00010
00011 extern "C" int typesize(int type, int count)
00012 {
00013 switch(type) {
00014 case CMPI_DOUBLE_PRECISION : return count*sizeof(double);
00015 case CMPI_INTEGER : return count*sizeof(int);
00016 case CMPI_REAL : return count*sizeof(float);
00017 case CMPI_COMPLEX: return 2*count*sizeof(double);
00018 case CMPI_LOGICAL: return 2*count*sizeof(int);
00019 case CMPI_CHAR:
00020 case CMPI_BYTE:
00021 case CMPI_PACKED:
00022 default:
00023 return 2*count;
00024 }
00025 }
00026
00027 extern "C" void FTN_NAME(CKEXIT, ckexit)()
00028 {
00029 CkExit();
00030 }
00031
00032 extern "C" void FTN_NAME(CKMYPE, ckmype)(int *pe)
00033 {
00034 *pe = CkMyPe();
00035 }
00036
00037 extern "C" void FTN_NAME(CKNUMPES, cknumpes)(int *npe)
00038 {
00039 *npe = CkNumPes();
00040 }
00041
00042 extern "C" void FTN_NAME(CKPRINTF, ckprintf)(const char *format, ...)
00043 {
00044 int ifmt, str_len=0, temp_len, flag;
00045 int *i; float *f; double *d;
00046 char str[100], temp_fmt[10];
00047 int j;
00048
00049 va_list args;
00050 va_start(args,format);
00051 for (ifmt=0;;) {
00052 if (format[ifmt]=='$') break;
00053 if (format[ifmt]=='%') {
00054 temp_fmt[0]='%'; temp_len=1;
00055 ifmt++;
00056 for (j=0; ; j++) {
00057 flag=0;
00058 switch (format[ifmt]) {
00059 case 'i':
00060 case 'd':
00061 i = va_arg(args, int *);
00062 temp_fmt[temp_len] = 'i'; temp_fmt[++temp_len]='\0';
00063 str_len += sprintf(str+str_len,temp_fmt,*i);
00064 ifmt++;
00065 flag=1; break;
00066 case 'e':
00067 case 'f':
00068 f = va_arg(args, float *);
00069 temp_fmt[temp_len] = format[ifmt]; temp_fmt[++temp_len]='\0';
00070 str_len += sprintf(str+str_len,temp_fmt,*f);
00071 ifmt++;
00072 flag=1; break;
00073 case 'E':
00074 case 'F':
00075 d = va_arg(args, double *);
00076 temp_fmt[temp_len] = format[ifmt]+32; temp_fmt[++temp_len]='\0';
00077 str_len += sprintf(str+str_len,temp_fmt,*d);
00078 ifmt++;
00079 flag=1; break;
00080 default:
00081 if (format[ifmt]=='.' || (format[ifmt]>='0' && format[ifmt]<='9')) {
00082 temp_fmt[temp_len] = format[ifmt];
00083 temp_len++; ifmt++;
00084 }
00085 else {
00086 printf("Print format error!\n"); return;
00087 }
00088 }
00089 if (flag) break;
00090 }
00091 }
00092 else if (format[ifmt]=='\\') {
00093 ifmt++;
00094 if (format[ifmt]=='n') {
00095 str[str_len] = '\n';
00096 str_len++;
00097 ifmt++;
00098 }
00099 }
00100 else {
00101 str[str_len] = format[ifmt];
00102 str_len++;
00103 ifmt++;
00104 }
00105 }
00106 str[str_len]='\0';
00107 CkPrintf("%s",str);
00108
00109
00110 va_end(args);
00111 }
00112
00113 FLINKAGE int FTN_NAME(CHARM_IARGC,charm_iargc)(void) {
00114 return CkGetArgc()-1;
00115 }
00116
00117 FLINKAGE void FTN_NAME(CHARM_GETARG,charm_getarg)
00118 (int *i_p,char *dest,int destLen)
00119 {
00120 int i=*i_p;
00121 if (i<0) CkAbort("charm_getarg called with negative argument!");
00122 if (i>=CkGetArgc()) CkAbort("charm_getarg called with argument > iargc!");
00123 const char *src=CkGetArgv()[i];
00124 strcpy(dest,src);
00125 for (i=strlen(dest);i<destLen;i++) dest[i]=' ';
00126 }
00127
00128
00129
00130 FLINKAGE CmiInt8 FTN_NAME(CMIMEMORYUSAGE, cmimemoryusage) ()
00131 {
00132 CmiInt8 mem = CmiMemoryUsage();
00133 return mem;
00134 }
00135
00136 FLINKAGE CmiInt8 FTN_NAME(CMIMAXMEMORYUSAGE, cmimaxmemoryusage) ()
00137 {
00138 return CmiMaxMemoryUsage();
00139 }
00140
00141 FLINKAGE CmiFloat8 FTN_NAME(CMIWALLTIMER, cmiwalltimer) ()
00142 {
00143 return CmiWallTimer();
00144 }
00145
00146 FLINKAGE CmiFloat8 FTN_NAME(CKWALLTIMER, ckwalltimer) ()
00147 {
00148 return CkWallTimer();
00149 }
00150
00151 FLINKAGE CmiFloat8 FTN_NAME(CMICPUTIMER, cmicputimer) ()
00152 {
00153 return CmiCpuTimer();
00154 }
00155
00156 FLINKAGE CmiFloat8 FTN_NAME(CKCPUTIMER, ckcputimer) ()
00157 {
00158 return CkCpuTimer();
00159 }
00160
00161 FLINKAGE void FTN_NAME(CMIDISABLEISOMALLOC, cmidisableisomalloc) ()
00162 {
00163 CmiDisableIsomalloc();
00164 }
00165
00166 FLINKAGE void FTN_NAME(CMIENABLEISOMALLOC, cmienableisomalloc) ()
00167 {
00168 CmiEnableIsomalloc();
00169 }
00170
00171 FLINKAGE void FTN_NAME(CMIDISABLETLS, cmidisabletls) ()
00172 {
00173 CmiDisableTLS();
00174 }
00175
00176 FLINKAGE void FTN_NAME(CMIENABLETLS, cmienabletls) ()
00177 {
00178 CmiEnableTLS();
00179 }
00180
00181 FLINKAGE void FTN_NAME(CMIMEMORYCHECK, cmimemorycheck) ()
00182 {
00183 CmiMemoryCheck();
00184 }
00185
00186
00187
00188 FLINKAGE void FTN_NAME(INITBIGSIMTRACE, initbigsimtrace)(int *outputParams, int *outputtiming)
00189 {
00190 initBigSimTrace(*outputParams, *outputtiming);
00191 }
00192
00193 FLINKAGE void FTN_NAME(FINALIZEBIGSIMTRACE, finalizebigsimtrace)()
00194 {
00195 finalizeBigSimTrace();
00196 }
00197
00198 FLINKAGE void FTN_NAME(STARTTRACEBIGSIM, starttracebigsim)()
00199 {
00200 startTraceBigSim();
00201 }
00202
00203 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM1, endtracebigsim1)(char *eventName, int *stepno, double *p1, int len)
00204 {
00205 char str[128];
00206 strncpy(str,eventName, len);
00207 str[len] = 0;
00208 endTraceBigSim(str, *stepno, *p1);
00209 }
00210
00211
00212 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM2, endtracebigsim2)(char *eventName, int *stepno, double *p1, double *p2, int len)
00213 {
00214 char str[128];
00215 strncpy(str,eventName, len);
00216 str[len] = 0;
00217 endTraceBigSim(str, *stepno, *p1, *p2);
00218 }
00219
00220 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM3, endtracebigsim3)(char *eventName, int *stepno, double *p1, double *p2, double *p3, int len)
00221 {
00222
00223 char str[128];
00224 strncpy(str,eventName, len);
00225 str[len] = 0;
00226 endTraceBigSim(str, *stepno, *p1, *p2, *p3);
00227 }
00228
00229 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM4, endtracebigsim4)(char *eventName, int *stepno, double *p1, double *p2, double *p3, double *p4, int len)
00230 {
00231
00232 char str[128];
00233 strncpy(str,eventName, len);
00234 str[len] = 0;
00235 endTraceBigSim(str, *stepno, *p1, *p2, *p3, *p4);
00236 }
00237
00238 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM5, endtracebigsim5)(char *eventName, int *stepno, double *p1, double *p2, double *p3, double *p4, double *p5, int len)
00239 {
00240
00241 char str[128];
00242 strncpy(str,eventName, len);
00243 str[len] = 0;
00244 endTraceBigSim(str, *stepno, *p1, *p2, *p3, *p4, *p5);
00245 }
00246
00247 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM6, endtracebigsim6)(char *eventName, int *stepno, double *p1, double *p2, double *p3, double *p4, double *p5, double *p6, int len)
00248 {
00249
00250 char str[128];
00251 strncpy(str,eventName, len);
00252 str[len] = 0;
00253 endTraceBigSim(str, *stepno, *p1, *p2, *p3, *p4, *p5, *p6);
00254 }
00255
00256 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM7, endtracebigsim7)(char *eventName, int *stepno, double *p1, double *p2, double *p3, double *p4, double *p5, double *p6, double *p7, int len)
00257 {
00258
00259 char str[128];
00260 strncpy(str,eventName, len);
00261 str[len] = 0;
00262 endTraceBigSim(str, *stepno, *p1, *p2, *p3, *p4, *p5, *p6, *p7);
00263 }
00264
00265 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM8, endtracebigsim8)(char *eventName, int *stepno, double *p1, double *p2, double *p3, double *p4, double *p5, double *p6, double *p7, double *p8, int len)
00266 {
00267
00268 char str[128];
00269 strncpy(str,eventName, len);
00270 str[len] = 0;
00271 endTraceBigSim(str, *stepno, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8);
00272 }
00273
00274 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM9, endtracebigsim9)(char *eventName, int *stepno, double *p1, double *p2, double *p3, double *p4, double *p5, double *p6, double *p7, double *p8, double *p9, int len)
00275 {
00276
00277 char str[128];
00278 strncpy(str,eventName, len);
00279 str[len] = 0;
00280 endTraceBigSim(str, *stepno, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9);
00281 }
00282
00283 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM10, endtracebigsim10)(char *eventName, int *stepno, double *p1, double *p2, double *p3, double *p4, double *p5, double *p6, double *p7, double *p8, double *p9, double *p10, int len)
00284 {
00285
00286 char str[128];
00287 strncpy(str,eventName, len);
00288 str[len] = 0;
00289 endTraceBigSim(str, *stepno, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10);
00290 }
00291
00292 FLINKAGE void FTN_NAME(ENDTRACEBIGSIM11, endtracebigsim11)(char *eventName, int *stepno, double *p1, double *p2, double *p3, double *p4, double *p5, double *p6, double *p7, double *p8, double *p9, double *p10, double *p11, int len)
00293 {
00294
00295 char str[128];
00296 strncpy(str,eventName, len);
00297 str[len] = 0;
00298 endTraceBigSim(str, *stepno, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10, *p11);
00299 }
00300
00301
00302
00303