Commit 76dd2fec authored by Iulian Grindeanu's avatar Iulian Grindeanu Committed by vijaysm
Browse files

First crack at fortran bindings by following iMesh design.

- Introduce imoab_protos.h
- Use extern "C" so that the routine names are not mangled.
  Otherwise fortran bindings will not work
parent 659d2b2e
......@@ -27,6 +27,11 @@ copy it in this folder (imoab/src/mhdf) temporarily; after imoab is part of moab
// global variables ; should they be organized in a structure, for easier references?
// or how do we keep them global?
#ifdef __cplusplus
extern "C" {
#endif
Interface * MBI = 0;
// we should also have the default tags stored, initialized
Tag gtags[5]; // material, neumann, dirichlet, globalID, partition tag
......@@ -96,10 +101,10 @@ ErrCode iMOABInitialize( int argc, iMOAB_String* argv )
}
}
refCountMB++;
return MB_SUCCESS;
return 0;
}
#if 0
/**
\fn ErrorCode iMOABInitializeFortran( )
\brief Initialize the iMOAB interface implementation from Fortran driver and create the MOAB instance, if not created already (reference counted).
......@@ -107,8 +112,26 @@ ErrCode iMOABInitialize( int argc, iMOAB_String* argv )
<B>Operations:</B> Collective
*/
ErrorCode iMOABInitializeFortran( );
#endif
ErrCode iMOABInitializeFortran()
{
if (0 == refCountMB) {
MBI = new Core();
// retrieve the default tags
const char* const shared_set_tag_names[] = { MATERIAL_SET_TAG_NAME,
NEUMANN_SET_TAG_NAME, DIRICHLET_SET_TAG_NAME, GLOBAL_ID_TAG_NAME };
// blocks, visible surfaceBC(neumann), vertexBC (Dirichlet), global id, parallel partition
for (int i = 0; i < 4; i++) {
ErrorCode rval = MBI->tag_get_handle(shared_set_tag_names[i], 1,
MB_TYPE_INTEGER, gtags[i], MB_TAG_ANY);
if (MB_SUCCESS != rval)
return 1;
}
}
refCountMB++;
return 0;
}
/**
\fn ErrorCode iMOABFinalize()
......@@ -171,7 +194,7 @@ ErrCode RegisterApplication( iMOAB_String app_name, MPI_Comm* comm, iMOAB_AppID
appDatas.push_back(app_data); // it will correspond to app_FileSets[*pid] will be the file set of interest
return 0;
}
#if 0
/**
\fn ErrorCode RegisterFortranApplication( iMOAB_String app_name, int* comm, iMOAB_AppID pid, int app_name_length )
\brief Register a Fortran-basedapplication - Create a unique application ID and bootstrap interfaces for further queries.
......@@ -189,8 +212,40 @@ ErrCode RegisterApplication( iMOAB_String app_name, MPI_Comm* comm, iMOAB_AppID
*/
ErrorCode RegisterFortranApplication( iMOAB_String app_name, int* comm, iMOAB_AppID pid, int app_name_length );
ErrCode RegisterFortranApplication( iMOAB_String app_name, int* comm, iMOAB_AppID pid, int app_name_length )
{
std::string name(app_name);
if (appIdMap.find(name)!=appIdMap.end())
{
std::cout << " application already registered \n";
return 1;
}
*pid = unused_pid++;
appIdMap[name] = *pid;
// now create ParallelComm and a file set for this application
// convert from fortran communicator to a c communicator
// see transfer of handles
// http://www.mpi-forum.org/docs/mpi-2.2/mpi22-report/node361.htm
MPI_Comm ccomm = MPI_Comm_f2c( (MPI_Fint) *comm);
ParallelComm * pco = new ParallelComm(MBI, ccomm);
#if 1
int index = pco->get_id(); // t could be useful to get app id from pcomm instance ...
assert(index==*pid);
#endif
pcomms.push_back(pco);
// create now the file set that will be used for loading the model in
EntityHandle file_set;
ErrorCode rval = MBI->create_meshset(MESHSET_SET, file_set);
if (MB_SUCCESS != rval )
return 1;
appData app_data;
app_data.file_set=file_set;
appDatas.push_back(app_data); // it will correspond to app_FileSets[*pid] will be the file set of interest
return 0;
}
/**
\fn ErrorCode DeregisterApplication( iMOAB_AppID pid )
\brief De-Register application: delete mesh (set) associated with the application ID
......@@ -1427,3 +1482,8 @@ ErrCode GetNeighborVertices(iMOAB_AppID pid, iMOAB_LocalID* local_vertex_ID, int
return 0;
}
#endif
#ifdef __cplusplus
}
#endif
......@@ -38,6 +38,7 @@ Comments from Mike and Emily:
#define iMOAB_LocalID int
#define ErrCode int
#include "imoab_protos.h"
/*
* tag types can be: dense/sparse, int/ double/entityhandle , they could be on both elements and vertices
*/
......@@ -49,6 +50,10 @@ enum MOAB_TAG_TYPE { DENSE_INTEGER = 0,
SPARSE_ENTITYHANDLE
};
#ifdef __cplusplus
extern "C" {
#endif
/**
\fn ErrCode iMOABInitialize( int argc, iMOAB_String* argv )
\brief Initialize the iMOAB interface implementation and create the MOAB instance, if not created already (reference counted).
......@@ -471,4 +476,8 @@ ErrCode GetNeighborElements(iMOAB_AppID pid, iMOAB_LocalID * local_index, int* n
*/
ErrCode GetNeighborVertices(iMOAB_AppID pid, iMOAB_LocalID* local_vertex_ID, int* num_adjacent_vertices, iMOAB_LocalID* adjacent_vertex_IDs);
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
program fdriver
C include '/home/iulian/3rdparty/mpich-3.1/install/include/mpif.h'
include 'mpif.h'
integer ierr, num_procs, my_id
integer pid
character*10 appname
call MPI_INIT ( ierr )
c find out MY process ID, and how many processes were started.
call MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr)
call MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)
if (my_id .eq. 0) then
print *, " I'm process ", my_id, " out of ",
& num_procs, " processes."
end if
ierr = iMOABInitializeFortran()
appname = 'PROTEUS'
ierr = RegisterFortranApplication(appname, MPI_COMM_WORLD, pid)
ierr = DeregisterApplication(pid)
ierr = iMOABFinalize()
call MPI_FINALIZE ( ierr )
stop
end
# MOAB_DIR points to top-level install dir, below which MOAB's lib/ and include/ are located
MOAB_BUILD_DIR := /homes/iulian/source/MOAB14
#MOAB_BUILD_DIR := /home/iulian/source/MOAB14
MOAB_DIR := /homes/iulian/lib/moab14
#MOAB_DIR := /home/iulian/lib/parallel/moab14
ifneq ($(wildcard ${MOAB_DIR}/lib/moab.make),)
include ${MOAB_DIR}/lib/moab.make
......@@ -16,6 +19,12 @@ endif
driver: driver.o ../src/imoab.o ${MOAB_LIBDIR}/libMOAB.la
${MOAB_CXX} -o $@ $< ../src/imoab.o ${MOAB_LIBS_LINK}
fex: fex.o ../src/imoab.o ${MOAB_LIBDIR}/libMOAB.la
${IMESH_FC} -o $@ $< ../src/imoab.o ${MOAB_LIBS_LINK} -lstdc++
fex.o: fex.F
mpif77 ${FCFLAGS} -c $<
clean:
rm -rf *.o *.mod *.h5m ${ALLEXAMPLES}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment