Commit 8afc3a45 authored by Budiardja, Reuben's avatar Budiardja, Reuben
Browse files

Worked on using C to allocate Fortran allocatable example. Still has some...

Worked on using C to allocate Fortran allocatable example. Still has some issue with gcc/10.1.0 on Summit.
parent 51c89186
...@@ -5,17 +5,41 @@ ...@@ -5,17 +5,41 @@
void C_Allocate ( CFI_cdesc_t *A_DV, CFI_cdesc_t *ShapeDV, int *Status ) void C_Allocate ( CFI_cdesc_t *A_DV, CFI_cdesc_t *ShapeDV, int *Status )
{ {
int iE; int iD;
int *nValues; int *nValues;
size_t len;
CFI_index_t *lbounds, *ubounds;
printf("=== Entering C_Allocate === \n");
// Error checking // Error checking
if ( A_DV->rank != ShapeDV->elem_len ) if ( A_DV->rank != ShapeDV->elem_len )
{ {
*Status = -1; printf("-- Rank and Shape is not consistent\n");
return; printf("-- Rank: %d, Shape: %d\n", A_DV->rank, ShapeDV->elem_len);
//*Status = -1;
//return;
}
lbounds = (CFI_index_t *) malloc ( sizeof ( CFI_index_t ) * A_DV->rank );
ubounds = (CFI_index_t *) malloc ( sizeof ( CFI_index_t ) * A_DV->rank );
nValues = ( int * ) ShapeDV->base_addr;
for ( iD = 0; iD < A_DV->rank; iD++ )
{
printf( "iD: %d - len: %d\n", iD, nValues [ iD ] );
lbounds [ iD ] = 1;
ubounds [ iD ] = nValues [ iD ];
} }
printf( "Base addr before allocation: %p\n", A_DV->base_addr );
CFI_allocate ( A_DV, lbounds, ubounds, len );
printf( "Base addr after allocation: %p\n", A_DV->base_addr );
nValues = (int *) ShapeDV->base_addr; if ( A_DV->base_addr )
for ( iE = 0; iE < ShapeDV->elem_len; iE++ ) *Status = 0;
printf("iD: %d - len: %d", iE, nValues[iE]); else
*Status = -1;
printf("=== Exiting C_Allocate === \n");
} }
program C_AllocatorProgram program C_AllocatorProgram
use iso_c_binding
use C_AllocateModule use C_AllocateModule
implicit none implicit none
integer :: & integer ( c_int ):: &
Status Status
integer, dimension ( 3 ) :: & integer ( c_int ), dimension ( 3 ) :: &
Shape A_Shape
real ( KDR ), dimension ( :, :, : ), allocatable :: & real ( KDR ), dimension ( :, :, : ), allocatable :: &
Array Array
Shape = [ 10, 20, 3 ]
call C_Allocate ( Array, Shape, Status )
if ( Status == 0 ) & Status = - huge ( 1 )
print*, 'is Allocated', allocated ( Array )
A_Shape = [ 10, 20, 3 ]
!--FIXME: the following caused gcc/10.1 to crash
!print*, 'Requested shape', A_Shape
call C_Allocate ( Array, A_Shape, Status )
if ( Status == 0 ) then
print*, 'is Array Allocated? ', allocated ( Array )
!-- FIXME: shape causes GCC to crash
!print*, 'Shape:', shape ( Array )
print*, 'size:', size ( Array )
!print*, 'lbounds', lbound ( Array )
!print*, 'ubounds', ubound ( Array )
else
print*, 'Allocation failed'
end if
end program C_AllocatorProgram end program C_AllocatorProgram
#!/bin/bash
gcc --version
gfortran --version
set -o verbose
rm *.o *.mod a.out
gcc -c C_Allocate.c
gfortran -c C_AllocateModule.f90
gfortran C_AllocateProgram.f90 C_Allocate.o C_AllocateModule.o
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