Commits

Christos Kannas committed 5bf7bfc

Update: FORTRAN90 Interface to INTEGRATE function.

  • Participants
  • Parent commits 9402e96
  • Branches CUDA

Comments (0)

Files changed (4)

 
 FILE * param_headerFile   = 0;
 FILE * CUDA_headerFile = 0; /* ckannas 20140130 */
+FILE * integrateFortranFile = 0; /* ckannas 20140201 */
 FILE * initFile = 0; /*  mz_rs_20050117 */
 FILE * driverFile = 0;
 FILE * integratorFile = 0;
 extern FILE * stochasticFile;
 extern FILE * utilFile;
 extern FILE * CUDA_headerFile; /* ckannas 20140130 */
+extern FILE * integrateFortranFile; /* ckannas 20140201 */
 
 extern FILE * currentFile;
 

File src/code_cuda_c.c

     OpenFile( &driverFile, rootFileName, "_Main.c", "Main Program File" );
     OpenFile( &integratorFile, rootFileName, "_Integrator.c", 
                     "Numerical Integrator (Time-Stepping) File" );
+    OpenFile( &integrateFortranFile, rootFileName, "_Integrator.f90", 
+                    "Numerical Integrator (Time-Stepping) File" );
     OpenFile( &linalgFile, rootFileName, "_LinearAlgebra.c", 
                     "Linear Algebra Data and Routines File" );
     OpenFile( &functionFile, rootFileName, "_Function.cu", 
   
   CommentFunctionEnd( INTEGRATE );
   FreeVariable( INTEGRATE );
+
+  /* Generate FORTRAN Interface to Integrator that is CUDA enabled */
+  if(useLang == CUDA_C_LANG)
+    GenerateFortranInteface();
+}
+
+
+
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+void GenerateFortranInteface()
+{
+    int TIN, TOUT, INTEGRATE, initial_useLang = useLang;
+    char *c_real;
+
+    if(real == DOUBLE)
+        c_real = "C_DOUBLE";
+    else
+        c_real = "C_FLOAT";
+
+    /* change language to Fortran90 to create an interface for the Integrate function */
+    useLang = F90_LANG;
+    UseFile(integrateFortranFile);
+    F90_Inline("MODULE %s_Integrate", rootFileName );
+    NewLines(2);
+    F90_Inline("\tIMPLICIT NONE");
+    NewLines(1);
+    F90_Inline("\tINTERFACE");
+    //
+    TIN = DefElm( "TIN", real, "Start Time for Integration");
+    TOUT = DefElm( "TOUT", real, "End Time for Integration");
+    INTEGRATE = DefFnc( "INTEGRATE", 2, "Integrator routine");
+    //
+    F90_Inline("\tSUBROUTINE INTEGRATE (TIN, TOUT) BIND(C, name=\"INTEGRATE\")");
+    NewLines(1);
+    /* Interface body... */
+    F90_Inline("\t\tUSE ISO_C_BINDING, ONLY: %s", c_real);
+    NewLines(1);
+    F90_Inline("\t\tREAL(%s), VALUE, INTENT(IN) :: TIN", c_real);
+    F90_Inline("\t\tREAL(%s), VALUE, INTENT(IN) :: TOUT", c_real);
+    NewLines(1);
+    F90_Inline("\tEND SUBROUTINE INTEGRATE");
+    F90_Inline("\tEND INTERFACE");
+    NewLines(2);
+    F90_Inline("END MODULE %s_Integrate", rootFileName );
+    //
+    FreeVariable( INTEGRATE );
 }
 
 
   printf("\nKPP is generating the driver from %s.f90:", driver);
   printf("\n    - %s_Main",rootFileName);
   
-  if ( (useLang == F77_LANG)||(useLang == F90_LANG)||(useLang == C_LANG) )
+  if ( (useLang == F77_LANG)||(useLang == F90_LANG)||(useLang == C_LANG)||(useLang == CUDA_C_LANG) )
     GenerateIntegrator();
   
   /* mz_rs_20050518+ no driver file if driver = none */