checked in f90charm into langs
authorGengbin Zheng <gzheng@illinois.edu>
Fri, 15 Dec 2000 21:23:22 +0000 (21:23 +0000)
committerGengbin Zheng <gzheng@illinois.edu>
Fri, 15 Dec 2000 21:23:22 +0000 (21:23 +0000)
src/langs/f90charm/charmf.C [new file with mode: 0644]
src/langs/f90charm/charmf.h [new file with mode: 0644]
src/langs/f90charm/f90main.C [new file with mode: 0644]
src/langs/f90charm/f90main.ci [new file with mode: 0644]
src/langs/f90charm/f90main.h [new file with mode: 0644]
src/langs/f90charm/futil.f90 [new file with mode: 0644]

diff --git a/src/langs/f90charm/charmf.C b/src/langs/f90charm/charmf.C
new file mode 100644 (file)
index 0000000..a60a77c
--- /dev/null
@@ -0,0 +1,113 @@
+/*   define some FORTRAN interface for charm++ kernel functions
+     Gengbin Zheng    12/15/2000
+
+TODO:
+   add other fortran name styles like all captial.
+*/
+#include "charm++.h"
+#include <stdarg.h>
+#include "charmf.h"
+
+extern "C" int typesize(int type, int count)
+{
+  switch(type) {
+    case CMPI_DOUBLE_PRECISION : return count*sizeof(double);
+    case CMPI_INTEGER : return count*sizeof(int);
+    case CMPI_REAL : return count*sizeof(float);
+    case CMPI_COMPLEX: return 2*count*sizeof(double);
+    case CMPI_LOGICAL: return 2*count*sizeof(int);
+    case CMPI_CHAR:
+    case CMPI_BYTE:
+    case CMPI_PACKED:
+    default:
+      return 2*count;
+  }
+}         
+
+extern "C" void ckexit_()
+{
+  CkExit();
+}
+
+extern "C" void ckmype_(int *pe)
+{
+  *pe = CkMyPe();
+}
+
+extern "C" void cknumpes_(int *npe)
+{
+  *npe = CkNumPes();
+}
+
+extern "C" void ckprintf_(const char *format, ...)
+{
+  int ifmt, format_len, str_len=0, temp_len, flag;
+  int *i; float *f; double *d;
+  char str[100], temp_fmt[10];
+  int j;
+
+  va_list args;
+  va_start(args,format);
+  //format_len = strlen(format);
+  //for (ifmt=0; ifmt<format_len;) {
+  for (ifmt=0;;) {
+    if (format[ifmt]=='$') break; // $ is end of input
+    if (format[ifmt]=='%') {
+      temp_fmt[0]='%'; temp_len=1;
+      ifmt++;
+      for (j=0; ; j++) {
+       flag=0;
+       switch (format[ifmt]) {
+       case 'i': 
+       case 'd':
+         i = va_arg(args, int *);
+         temp_fmt[temp_len] = 'i'; temp_fmt[++temp_len]='\0';
+         str_len += sprintf(str+str_len,temp_fmt,*i); 
+         ifmt++;
+         flag=1; break; 
+       case 'e':
+       case 'f':
+         f = va_arg(args, float *);
+         temp_fmt[temp_len] = format[ifmt]; temp_fmt[++temp_len]='\0';
+         str_len += sprintf(str+str_len,temp_fmt,*f); 
+         ifmt++;
+         flag=1; break;
+       case 'E':
+       case 'F':
+         d = va_arg(args, double *);
+         temp_fmt[temp_len] = format[ifmt]+32; temp_fmt[++temp_len]='\0';
+         str_len += sprintf(str+str_len,temp_fmt,*d); 
+         ifmt++;
+         flag=1; break;
+       default:
+         if ((format[ifmt]=='.')&&(format[ifmt]<='9')||(format[ifmt]>='0')) {
+           temp_fmt[temp_len] = format[ifmt];
+           temp_len++; ifmt++;
+         }
+         else {
+           printf("Print format error!\n"); return;
+         }
+       } // end of switch
+       if (flag) break; // break for(j=0;;j++)
+      }
+    }
+    else if (format[ifmt]=='\\') {
+      ifmt++;
+      if (format[ifmt]=='n') { 
+       str[str_len] = '\n'; 
+       str_len++;
+       ifmt++;
+      }
+    }
+    else {
+      str[str_len] = format[ifmt]; 
+      str_len++;
+      ifmt++;
+    }
+  } // for (ifmt=0;;)
+  str[str_len]='\0';
+  CkPrintf("%s",str);
+  //vprintf(format, args);
+  //fflush(stdout);
+  va_end(args);
+}
diff --git a/src/langs/f90charm/charmf.h b/src/langs/f90charm/charmf.h
new file mode 100644 (file)
index 0000000..65202c8
--- /dev/null
@@ -0,0 +1,11 @@
+
+#define CMPI_DOUBLE_PRECISION 0
+#define CMPI_INTEGER 1
+#define CMPI_REAL 2
+#define CMPI_COMPLEX 3
+#define CMPI_LOGICAL 4
+#define CMPI_CHAR 5
+#define CMPI_BYTE 6
+#define CMPI_PACKED 7 
+
+extern "C" int typesize(int type, int count);
diff --git a/src/langs/f90charm/f90main.C b/src/langs/f90charm/f90main.C
new file mode 100644 (file)
index 0000000..90053c6
--- /dev/null
@@ -0,0 +1,81 @@
+#include "f90main.h"
+
+#if AMPI_FORTRAN
+#if CMK_FORTRAN_USES_ALLCAPS
+extern "C" void F90CHARMMAIN(int, char **);
+#else
+extern "C" void f90charmmain_(int, char **);
+#endif // CMK_FORTRAN_USES_ALLCAPS
+#else
+extern "C" void f90charmmain(int, char **);
+#endif
+
+extern void _initCharm(int argc, char **argv);
+
+CkChareID mainhandle;
+
+extern "C" void conversemain_(int *argc,char _argv[][80],int length[])
+{
+  int i;
+  char **argv = new char*[*argc+2];
+
+  for(i=0;i <= *argc;i++) {
+    if (length[i] < 100) {
+      _argv[i][length[i]]='\0';
+      argv[i] = &(_argv[i][0]);
+    } else {
+      argv[i][0] = '\0';
+    }
+  }
+  argv[*argc+1]=0;
+
+  ConverseInit(*argc, argv, _initCharm, 0, 0);
+}
+
+
+f90main::f90main(CkArgMsg *msg)
+{
+  int argc = msg->argc;
+  char **argv = msg->argv;
+  delete msg;
+
+  count = 0;
+  mainhandle = thishandle;
+
+#if AMPI_FORTRAN
+#if CMK_FORTRAN_USES_ALLCAPS
+  F90CHARMMAIN(argc, argv);
+#else
+  f90charmmain_(argc, argv);
+#endif // CMK_FORTRAN_USES_ALLCAPS
+#else
+  f90charmmain(argc, argv);
+#endif
+
+  /*
+  int executor_grp = CProxy_executor::ckNew(); 
+  CProxy_executor grp(executor_grp);
+  grp.run();
+  */
+}
+
+void f90main::done()
+{
+  count++;
+  if (count == CkNumPes()) CkExit();
+}
+
+/*
+void executor::run()
+{
+  CkPrintf("[%d] running.\n", CkMyPe());
+  int i;
+  main_(&i);
+  CkPrintf("%d\n", i);
+  CProxy_main mp(mainhandle);
+  mp.done();
+}
+*/
+
+
+#include "f90main.def.h"
diff --git a/src/langs/f90charm/f90main.ci b/src/langs/f90charm/f90main.ci
new file mode 100644 (file)
index 0000000..9374fba
--- /dev/null
@@ -0,0 +1,11 @@
+module f90main {
+//  extern module hello;
+
+  readonly CkChareID mainhandle;
+
+  mainchare f90main {
+    entry f90main();
+    entry void done(void);
+  };
+
+}
diff --git a/src/langs/f90charm/f90main.h b/src/langs/f90charm/f90main.h
new file mode 100644 (file)
index 0000000..ed34dbf
--- /dev/null
@@ -0,0 +1,11 @@
+
+#include "f90main.decl.h"
+
+class f90main: public Chare
+{
+  int count;
+  public:
+  f90main(CkArgMsg *);
+  void done();
+};
+
diff --git a/src/langs/f90charm/futil.f90 b/src/langs/f90charm/futil.f90
new file mode 100644 (file)
index 0000000..1fde4de
--- /dev/null
@@ -0,0 +1,16 @@
+      PROGRAM main1
+
+      character*80 argv(0:99)
+      integer argc, length(0:99)
+      integer i,ierr
+      
+!      argc = ipxfargc()
+      
+!      do i = 0,argc
+!         call pxfgetarg(i,argv(i),length(i),ierr)
+!         if (ierr .ne. 0) print*,'Arg ',i,' error'
+!      end do
+      call conversemain(argc,argv,length)
+
+      END
+