Opencoarrays Non Fortran Main

Hello,
I am trying to call a simple Opencoarrays program with non Fortran main based on Making sure you're not a bot! this wiki. Just wanted your help, after compiling coarray part using -fcoarray=lib, compiling c parts gives error. Following is the error

libcaf.h:236:31: error: expected ‘)’ before ‘,’ token
236 | void PREFIX (register) (size_t, caf_register_t, caf_token_t *,
| ^
| )
main.c: In function ‘main’:
main.c:11:5: error: implicit declaration of function ‘gfortran_caf_init’ [-Wimplicit-function-declaration]
11 | gfortran_caf_init(*argc, ***argv);
| ^~~~~~~~~~~~~~~~~
main.c:16:5: error: implicit declaration of function ‘gfortran_caf_finish’ [-Wimplicit-function-declaration]
16 | gfortran_caf_finish ();

I am attaching the fortran file

coarray_module.f90 (338 Bytes)

The C calling code is

#include <stdio.h>
#include <libcaf.h> // Include the header file

extern void coarray_hello(); // Fortran subroutine

int main(int *argc, char ***argv) {

_gfortran_caf_init(*argc, ***argv);

printf("Calling Fortran coarray subroutine from C...\n");
coarray_hello();

_gfortran_caf_finish ();
return 0;

}

Somehow this part is not compiling, and giving error.

@rouson Just your feedback, what I am attempting is correct or not. Your valuable feedback in making it working will be very helpful.

Best Regards

Apurva

1 Like

Some success with the C main interface, but still the finalization is not working. It worked only without finalization

Following is the partially working C main

#include <stdio.h>

extern void coarray_hello(); // Fortran subroutine
extern void _gfortran_caf_init();
//extern void _gfortran_caf_finish();

void main(int *argc, char ***argv) {

_gfortran_caf_init(&argc, &argv);

printf("Calling Fortran coarray subroutine from C...\n");
coarray_hello();

//_gfortran_caf_finish();

}

If you notice finalization has been commented. I got following partial output on run

Calling Fortran coarray subroutine from C…
** Hello from image 1 of 4**
Calling Fortran coarray subroutine from C…
** Hello from image 2 of 4**

We get error due to missing of finalization in C main.

Help me in getting rid of this error.