Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Dllexport Function in Subroutine

Carsten_A_
Beginner
637 Views

Hello,

following Code is okay. But I am not sure how to export/import that routines!? The subroutine calls the function.

subroutine RandomFibers(nFib, r, nCellsY, nCellsZ, initW, initH)
    !DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'RandomFibers' ::RandomFibers
    implicit none
    real, dimension (nFib) ::  fibCoY, fibCoZ, ranR  
    integer i, j, k, counter, nFib, nFibCell, nCellsY, nCellsZ, nRestFib                                                                             
    real(8) y, z, rad, delta, dwide, dheight, initW, initH
    
    ! parameter for ploting
    real, dimension (nCellsY) ::  yMin, yMax
    real, dimension (nCellsZ) ::  zMin, zMax
    real r
    ! calculate and round number of fibers per Cell
    nFibCell = (nFib / ( nCellsY * nCellsZ))           
   
    ! calculate boundaries (dwide / dheight) of cell from initial RVE size 
    dwide = delta(nCellsY, initW)
    dheight = delta(nCellsZ, initH)
   
  
    !calculate random fiber coordinates in the boundaries of each cell 
    call random_seed
    do i=1, nFib
        call RANDOM_NUMBER(y)
        call RANDOM_NUMBER(z)
        call RANDOM_NUMBER(rad)
        fibCoY(i) = 0.0 + y * (initW - 0.0)
        fibCoZ(i) = 0.0 + z * (initH - 0.0)
        !ranR(counter) = (rad - 0.5) * r / 20.0 + r !calculate random fiber radiu
    end do   
end subroutine RandomFibers


function delta(nCells, initLeng)
    !DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'delta' ::delta
    implicit none
    integer nCells
    real(8) initLeng, delta 
    delta = (initLeng - 0.0) / nCells
end function

execute program:

program run

    !DEC$ ATTRIBUTES DLLIMPORT, ALIAS: 'delta' ::delta

    !DEC$ ATTRIBUTES DLLIMPORT, ALIAS: 'RandomFibers' ::RandomFibers

    implicit none
    integer nFib, nCellsY, nCellsZ
    real(8) initW, initH, dy, dz
    real, dimension (11) ::  yLeft, yRight
    real, dimension (11) ::  zBottom, zTop
    real r
    nFib = 900

    r = 0.2
    nCellsY = 30
    nCellsZ = 30
    initW = 20.0
    initH = 20.0
    
    Call RandomFibers(nFib, r, nCellsY, nCellsZ, initW, initH)

end program run

 

0 Kudos
1 Solution
Steven_L_Intel1
Employee
637 Views

This looks ok to me. You don't need to export/import delta as it is not referenced in the main program. Any particular reason you used ALIAS?

View solution in original post

0 Kudos
2 Replies
Steven_L_Intel1
Employee
638 Views

This looks ok to me. You don't need to export/import delta as it is not referenced in the main program. Any particular reason you used ALIAS?

0 Kudos
Carsten_A_
Beginner
637 Views

Thanks Steve,

your are right. The Code is okay. The mistake was somewhere else!

I deleted the Alias because there are needless in my case. The whole line: "!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'delta' ::delta" I deleted as well.

0 Kudos
Reply