MxUI / MUI

Multiscale Universal Interface: A Concurrent Framework for Coupling Heterogeneous Solvers
http://mxui.github.io/
Apache License 2.0
54 stars 40 forks source link

fortran wrapper type error?? #100

Closed Kun-Qu closed 1 year ago

Kun-Qu commented 1 year ago
void mui_forget_upper_3d_f(mui_uniface_3d *uniface, double *upper, int *reset_log) {
    uniface->forget(*upper, static_cast<bool>(*reset_log));
}

In its fortran interface

    subroutine mui_forget_upper_3d_f(uniface,upper,reset_log) bind(C)
      import :: c_ptr,c_int,c_double
      type(c_ptr), intent(in), value :: uniface
      real(kind=c_double), intent(in), value :: upper
      integer(kind=c_int), intent(in), value :: reset_log
    end subroutine mui_forget_upper_3d_f

For arguments upper and reset_log, is the property value is right? since they are pointers in cpp?

SLongshaw commented 1 year ago

Thanks for the issue report, I believe the current implementation is correct here - as this is using Fortran's c-bind, it is typical to prototype the called c function as a pointer and then the Fortran subroutine not. You will see the same pattern throughout the entire wrapper, with variables that are actually pointers in the c code defined as double pointers and then set as type c_ptr in the Fortran subroutine.

I'm going to close this one as I believe the current implementation is correct.

Kun-Qu commented 1 year ago

In the cpp code, arguments 'upper' and 'reset_log' are the pointers. thus its fortran interface should be consistance. since fortran transfers the pointers of arguments by default so, the default mode should be used. that's why I think 'value' should not be present

if a argument in C function is transfered by value then we need value in the frotran interface.

image