00001
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <stdarg.h>
00011 #include <string.h>
00012
00013 #include "charm.h"
00014 #include "charm-api.h"
00015
00016
00017 extern "C" void CmiAbort(const char *why) {
00018 fprintf(stderr,"Fatal error> %s\n",why);
00019 abort();
00020 }
00021
00022 extern "C" void CmiPrintf(const char *fmt, ...) {
00023 va_list p; va_start(p, fmt);
00024 vfprintf(stdout,fmt,p);
00025 va_end(p);
00026 }
00027 extern "C" void CmiError(const char *fmt, ...) {
00028 va_list p; va_start(p, fmt);
00029 vfprintf(stderr,fmt,p);
00030 va_end(p);
00031 }
00032
00033 extern "C" void *CmiTmpAlloc(int size) {return malloc(size);}
00034 extern "C" void CmiTmpFree(void *p) {free(p);}
00035 extern "C" void __cmi_assert(const char *errmsg) { CmiAbort(errmsg);}
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 int _Cmi_mype=0;
00046 int _Cmi_numpes=1;
00047 int _Cmi_mynodesize=1;
00048 int _Cmi_mynode=0;
00049 int _Cmi_numnodes=1;
00050
00051
00052 double _cpu_speed_factor=0.0;
00053 CLINKAGE double CmiTimer(void) {return 0.0;}
00054 #ifndef CmiWallTimer
00055 CLINKAGE double CmiWallTimer(void) {return 0.0;}
00056 #endif
00057
00058
00059 #include "tcharmc.h"
00060 CLINKAGE void TCHARM_Migrate(void) {}
00061
00062 enum {tc_global_max=64};
00063 void *tc_globals[tc_global_max];
00064 void TCHARM_Set_global(int globalID,void *new_value,TCHARM_Pup_global_fn pup_or_NULL) {
00065 tc_globals[globalID]=new_value;
00066 }
00067 void *TCHARM_Get_global(int globalID) {
00068 return tc_globals[globalID];
00069 }
00070
00071
00072
00073 CLINKAGE int TCHARM_Register(void *data,TCHARM_Pup_fn pfn) {return -1;}
00074 FORTRAN_AS_C_RETURN(int,TCHARM_REGISTER,TCHARM_Register,tcharm_register,
00075 (void *data,TCHARM_Pup_fn pfn),(data,pfn))
00076
00077 CLINKAGE void *TCHARM_Get_userdata(int id) {return 0;}
00078
00079 CLINKAGE void TCHARM_Done(int exitcode) { }
00080 FORTRAN_AS_C(TCHARM_DONE,TCHARM_Done,tcharm_done,(int *exitcode),(*exitcode))
00081
00082 CLINKAGE void TCHARM_Barrier(void) { }
00083 FORTRAN_AS_C(TCHARM_BARRIER,TCHARM_Barrier,tcharm_barrier,(void),())
00084
00085 CLINKAGE int TCHARM_Element(void) {return 0;}
00086 FORTRAN_AS_C_RETURN(int,TCHARM_ELEMENT,TCHARM_Element,tcharm_element,(void),())
00087
00088 CLINKAGE int TCHARM_Num_elements(void) {return 1;}
00089 FORTRAN_AS_C_RETURN(int,TCHARM_NUM_ELEMENTS,TCHARM_Num_elements,tcharm_num_elements,(void),())
00090
00091 CLINKAGE double TCHARM_Wall_timer(void) {return 0.0;}
00092 FORTRAN_AS_C_RETURN(double,TCHARM_WALL_TIMER,TCHARM_Wall_timer,tcharm_wall_timer,(void),())
00093
00094 #define FORTRAN_TCHARM_UNIMPLEMENTED(ROUTINE,routine) \
00095 FLINKAGE void FTN_NAME(TCHARM_##ROUTINE,tcharm_##routine)(void) \
00096 { CkAbort("Sorry, standalone mode does not have TCHARM_" #ROUTINE); }
00097
00098 FORTRAN_TCHARM_UNIMPLEMENTED(INIT,init)
00099 FORTRAN_TCHARM_UNIMPLEMENTED(CREATE,create)
00100 FORTRAN_TCHARM_UNIMPLEMENTED(MIGRATE,migrate)
00101 FORTRAN_TCHARM_UNIMPLEMENTED(SET_STACK_SIZE,set_stack_size)
00102 FORTRAN_TCHARM_UNIMPLEMENTED(CREATE_DATA,create_data)
00103 FORTRAN_TCHARM_UNIMPLEMENTED(MIGRATE_TO,migrate_to)
00104 FORTRAN_TCHARM_UNIMPLEMENTED(YIELD,yeild)
00105
00106
00107
00108 static char **saved_argv=NULL;
00109
00110 CLINKAGE int CmiGetArgFlagDesc(char **argv,const char *arg,const char *desc) {
00111 int i;
00112 saved_argv=argv;
00113 for (i=0;argv[i]!=NULL;i++)
00114 if (0==strcmp(argv[i],arg))
00115 {
00116 return 1;
00117 }
00118 return 0;
00119 }
00120
00121 CLINKAGE int CmiGetArgIntDesc(char **argv,const char *arg,int *optDest,const char *desc) {
00122 int i;
00123 saved_argv=argv;
00124 for (i=0;argv[i]!=NULL;i++)
00125 if (0==strcmp(argv[i],arg))
00126 {
00127 *optDest = atoi(argv[i+1]);
00128 return 1;
00129 }
00130 return 0;
00131 }
00132
00133 FLINKAGE void FTN_NAME(TCHARM_GETARG,tcharm_getarg)(int *arg,char *dest,int destLen) {
00134 if (saved_argv==NULL)
00135 CkAbort("TCHARM_GETARG not supported in FEM_ALONE mode!\n");
00136 else {
00137 int i;
00138 const char *src=saved_argv[*arg];
00139 strcpy(dest,src);
00140 for (i=strlen(dest);i<destLen;i++) dest[i]=' ';
00141 }
00142 }
00143