You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Table of contents

1. Introduction

The document describes how to generate a LinkableComponent on Linux:

  • how to compile a shared library for a Fortran <engine>
  • how to port a C# wrapper for this shared library from Windows to Linux. The wrapper contains a class for accessing the Fortran Dll <engine>DllAccess and two outer classes <engine>DotNetAccess and <engine>Wrapper.

2. Technical prerequisites

2.1. Machine and OS of the test system

  • workstation with an Intel Xeon processor
  • 64bit Suse Linux Edition Desktop SLED 10.3 on the machine with the Fortran compiler
  • 64bit openSUSE 11.0 on the machine with the C# compiler

2.2. Mono for multi platform C#

  • Mono v. 1.9.1. for openSUSE 11.0 in 64 bit mode. V. 1.9.1. is the concrete term, but it is also referred to as Mono 2.0.
  • compiler gmcs 2.0.

2.3. Fortran 90 Compiler

  • Intel 64 bit Fortran Compiler v. 9.1.051

2. How to generate a shared library for a Fortran engine

2.1. General

During runtime the C# wrapper could only reference one Fortran shared library. All Fortran sources were compiled to one shared library with the following compiler options:
Compilation:

ifort -c -fPIC -convert big_endian -fpp *.f90
-c : compile to object (.o) only, do not link
-fPIC : generate position independent code (for shared libs)
-convert big_endian: the order in which a sequence of bytes is stored in a computer's memory,
here: most significant bytes first;
used, e.g. on mainframes and supercomputers.
-fpp : run Fortran preprocessor on source files prior to compilation

Linking the compiled objects:

ifort -shared *.o -o <sharedLibrary.so>

During runtime some fortran libraries must be accessible via LD_LIBRARY_PATH. In the following examples they are provided by the ifort compiler:

export LD_LIBRARY_PATH=/opt/intel/fce/9.1.051/lib:. // on 64bit systems
export LD_LIBRARY_PATH=/opt/intel/fc/9.1.051/lib:. // on 32bit systems

2.2. Ifort parameter bug

The ifort compiler v. 9.1.051 has a bug with public character parameters in modules.
Example:

ifort -shared *.o -o <sharedLibrary.so>
CHARACTER (LEN=40), PUBLIC, PARAMETER :: c_att_name(2)= &
/ 'title ', &
'history '/

The parameter c_att_name can not be accessed from outside the module. The solution is a function that exports the parameter as a return value. Now the values can be accessed from outside.

PUBLIC FUNCTION get_c_att_name ( idx ) &
RESULT(res)
...
CHARACTER (LEN=40) :: res
res = c_att_name(idx)
END FUNCTION get_c_att_name

3. How to port a C# wrapper from Windows to Linux

3.1. General

The Mono Guidelines Interop with Native Libaries gives general information about the interface between managed and unmanaged code.

The wrapper has three layers:

  • <engine>DllAccess.cs is the inner layer;
  • <engine>DotNetAccess.cs;
  • <engine>Wrapper.cs is a LinkableComponent and the outer layer.
    Compilation of the two inner layers:

    gmcs -target:library -out: <engine>DotNetAccess.dll <engine>DllAccess.cs
    <engine>DotNetAccess.cs
    Compilation of the outer layer:

    gmcs -target:library -out:<engine>Wrapper.dll -pkg:baw-geidotnet.pc,
    openmi-backbone.pc,openmi-devsupport.pc,openmi-spatial.pc,
    openmi-standard.pc,openmi-wrapper.pc *.cs
    -pkg: <name>.pc file (path and name) with information about a referenced shared library

  • No labels