Giter VIP home page Giter VIP logo

c-fortran-tests's Introduction

c-fortran-tests

C-Fortran Interoperability Test Repo

c-fortran-tests's People

Watchers

 avatar  avatar  avatar

Forkers

mabrunke

c-fortran-tests's Issues

Discussion about c-fortran interoperability

@bartnijssen, @mabrunke, and @apcraig -

I have a first attempt at using the Standard Fortran and C Interoperability on the master branch of this repo. It is working on my local machine using the newest versions gcc and gfortran but is failing on the HPC machines that use the Intel or older versions of the GNU compilers. I'll explain why I think that is later and hopefully one of you will have an idea of why that is.

Code Design

The code I have essentially tracks the desired workflow for what we want to see in the VIC/CN coupling (see UW-Hydro/VIC#174 for more information).

  1. Memory is created and initialized in C using a C-structure: cn_data_struct.
  2. A Fortran subroutine is developed that accepts the cn_data_struct as an argument
  3. The Fortran subroutine is able to operate directly on the cn_data_struct without a copy.

Looking at the code in this example, here where each of those 3 steps are done:

  1. The C function make_cn_struct creates and initializes an array of cn_data_structs.
  2. The Fortran subroutine use_cn_data_struct defines a derived type vic_cn_data_type that matches the cn_data_struct. The variable is defined as intent(inout) so any changes are applied to the original memory location of cn_data_struct.
  3. The Fortran subroutine use_cn_data_struct modifies the values of all members of the structure.

Outside of this example, it would probably make sense to put the definition of vic_cn_data_type in a MODULE so it would be available to other subroutines.

Now, the problem I mentioned earlier:

The cn is defined as an array of cn_data_structs, one for each elevation band. It seems like there is a problem passing arrays like this through the C-Fortran interoperability when you are using an assumed size or shape. This is the relevant line:

type(vic_cn_data_type), DIMENSION(:), intent(inout) :: cn_data

I'm sure there is a way to do this without assuming either the shape or the size but I wasn't able to get it to work. @mabrunke or @apcraig may have a better idea of how that could work. After all, I am passing all the relavent dimensions as arguments to the subroutine.

Useful links

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.