Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all 5691 articles
Browse latest View live

What are reasons for access violation?

$
0
0

In operator containing one reference to array element I have message:

forrtl: severe (157): Program Exception - access violation

That element could not be a reason - I check it. What are another possible reasons?


LNK2005: _WinMain@16 already defined

$
0
0

linking error - function already defined - where do I find more info?

how do I fix this problem?

What is the difference betwen "VISUAL FORTRAN COMPOSER XE" vs. "PARALLEL STUDIO XE COMPOSER FOR FORTRAN"

$
0
0

Hi everyone,

 

We have 2 licensed intel development tools in our group. They are  "VISUAL FORTRAN COMPOSER XE" and "PARALLEL STUDIO XE COMPOSER FOR FORTRAN".

We want to know the differences between them. Can someone help me explain the differences between them?

 

Thanks,

Hai

LNK2005 error

$
0
0

>building in Visual Studios

Compiling with Intel(R) Visual Fortran Compiler 19.0.4.245 [IA-32]..

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

>get error:

        Referenced in libifcoremt.lib(for_diags_intel.obj)
        Referenced in libifcoremt.lib(for_stop.obj)
        Referenced in libifcoremt.lib(for_exit.obj)
        Referenced in libifcoremt.lib(for_nt_open_proc.obj)
        Loaded ifqwin.lib(qwkentry.obj)
ifqwin.lib(qwkentry.obj) : error LNK2005: _WinMain@16 already defined in ib507p2.obj

>_WinMain@16 not in link messages before this error.  What is happening?

>How can I fix this?

 

 

dialog controls

$
0
0

i am new to the Intel Visual Fortran developer system, and have no local support help for

my problems, which I am trying to resolve one step at a time.  I have been able to compile

and link my legacy Fortran program, but now have a new problem.  when trying to run the

executable, a small widow appears with -

                    TODO:  Place dialog controls here.

I have no clue what this means.

            - RonA

 

 

create folder with time and date

$
0
0

hello

im having problems to create a simple folder with time and date and then create a file with custom filename, could someone please help me?

"USE IFPORT
LOGICAL(4) result
character(len=10) :: time,date
call date_and_time(time=time)
call date_and_time(date=date)
result = MAKEDIRQQ(time,date)
OPEN(UNIT=404, ACCESS='SEQUENTIAL', FORM='BINARY', FILE='/time,date/filename', STATUS='REPLACE', convert='big_endian')
CLOSE(unit=404)"

thank you for your attention

Famous message "forrtl: severe (157): Program Exception"

$
0
0

Well, I know that this subject has several topics in this forum. I tried to include my question in some of them, but all I found was locked, which is weird.

Anyway, the problem is ... I'm trying to do a simple test with a QuickWin program by using the classical "Hello World" example. The thing is ... when running a release with x64 compiler I got the famous message violation

"forrtl: severe (157): Program Exception - access violation"

However, when running this same code by using the Debug mode with x64 compiler... none problem is found (the same with Win32 compiler).

Any thoughts?

PS: I'm using VS 2010 with Intel Composer XE 2015.

 

Which individual components are required for developing Fortran Codes?

$
0
0

Hi, I am new to MS Visual Studio IDE. I don't understand which packages to install for using or developing Fortran based projects. I need to understand which are the bare minimum requirements for developing using Fortran in windows.

Also, I installed some packages (including Visual Studio SDK, which according to documentation should also install VS Shell, https://docs.microsoft.com/en-us/visualstudio/extensibility/internals/vi...) that I thought would be required, but I encountered the problem with this again and again:

Microsoft Visual Studio Shell* deprecation
Microsoft* has announced the stand-alone Microsoft Visual Studio Shell* will not be available for Visual Studio 2017. As such, we are no longer providing a standalone shell. 
An integrated shell is available as part of the full Microsoft Visual Studio bundle. Please refer to https://visualstudio.microsoft.com/vs/ for further information on the Microsoft Visual Studio product offerings. For any questions or requests please contact us at https://software.intel.com/en-us/support.

I think this is the problem when I once fired up Visual Studio and couldn't output any prompt, like simple 'Hello, World' through Fortran Code.

I don't think I was able to explain my problem completely. There are a lot of small issues which needs resolving. I want to do a fresh installation please guide me.


Memory leak in fortran 2003

$
0
0

I have a memory leak when using a "constructor"(which is just a static function) to create an initialize a derived type object.

I have two subroutines that seem to be equivalent, but one of them has a memory leak (mult_leak), while the other hasn't (mult_noleak).

I don't understand which is the difference.

 

program main
    use lala
    type(mytype) :: mt1, mt2, mt3
    integer :: i
    real, allocatable, dimension(:,:) :: dat
    allocate(dat(1000, 1000))
    dat = 1.5

    do i=1,10000000
        mt1 = creador(dat)
        mt2 = creador(dat)
        mt3 = mult_leak(mt1, mt2)
        if(modulo(i,1000)==0) then
            print*, i, mt3%dat(1,1)
        endif       
    end do

end program
module lala

    type mytype

        integer :: nx, ny
        real, allocatable, dimension(:,:) :: dat

        contains
            private
            procedure :: init
    end type

interface creador
    procedure p_creador
end interface

contains
    subroutine init(this, dat)
        class(mytype) :: this
        real, allocatable, dimension(:,:) :: dat
        integer, dimension(2) :: s
        s = shape(dat)
        this%nx = s(1)
        this%ny = s(2)

        allocate(this%dat, source=dat)
    end subroutine

    function p_creador(dat) result(res)
        type(mytype), allocatable :: res
        real, allocatable, dimension(:,:) :: dat

        allocate(res)
        call res%init(dat)
    end function

    function mult_noleak(cf1, cf2) result(cfres)
        class(mytype), intent(in) :: cf1, cf2
        class(mytype), allocatable :: cfres

        real, dimension(:,:), allocatable :: aux

        allocate(cfres)

        aux=cf1%dat * cf2%dat

        call cfres%init(aux)

    end function

    function mult_leak(cf1, cf2) result(cfres)
        class(mytype), intent(in) :: cf1, cf2
        class(mytype), allocatable :: cfres

        real, dimension(:,:), allocatable :: aux

        aux=cf1%dat * cf2%dat
        cfres = creador(aux)

    end function
end module

 

catastrophic error in SELECT RANK

$
0
0

Using ifort (IFORT) 19.1.0.075 20190522 beta, the following generates a catastrophic error:

  integer, dimension(2,2) :: y = reshape ([1,2,3,4],[2,2])
  integer, dimension(4) :: z = [1,2,3,4]
  integer :: i = 42
  call foo(y, "y")
  print '(a, 4i4)', "Return value of y = ", y
  call foo(z, "z")
  call foo(i, "i")
  print '(a, i2)', "Return value of i = ", i
  call bar(y)
contains
  subroutine foo(w, chr)
    integer, dimension(..) :: w
    character(1) :: chr
    select rank (x => w)
      rank (2)
        print '(a, 2i2)', chr//"(1,:) = ", x(1,:)
        print '(a)', chr//" rank 2"
        x = reshape ([10,11,12,13], [2,2])
      rank (0)
        print '(a,i2)', chr//" = ", x
        print '(a)', chr//" rank 0"
        x = 5
      rank (*)
        print '(a, 4i4)', chr//"(1,:) = ", x(1:4)
        print '(a)', chr//" is assumed size"
      rank default
        select rank (x)
          rank (1)
            print '(a, 4i4)', chr//"(1,:) = ", x
        end select
    end select
  end subroutine
  subroutine bar(x)
    integer, dimension(*) :: x
    call foo(x, "w")
  end
end

test.f90(27): catastrophic error: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
compilation aborted for test.f90 (code 1)

The line number is correct. The SELECT RANK following RANK DEFAULT is the cause of the problem. As far as I can tell from the F2018 standard it should be OK. Removing the inner SELECT RANK gives the expected result.

Strangely, replacing the offending block with:

...snip...

      rank default
!        print'(a, i4)', chr//" is default. Rank = ", rank(x)
        call foo (x, "q")

...snip...

the test compiles OK and outputs:

q(1,:) = 1012
q rank 2

Uncommenting the PRINT statement causes a segfault.

Best regards

Paul

 

 

Intel Fortran runtime libraries with msi

$
0
0

1) We are planning on using the msi file that they provide (ww_ifort_redist_intel64_2019.0.117.msi) to install the Intel Fortran runtime libraries. Is there any documentation we could get that details command line switches for things like running silently, etc.?

2) Programmatically. what should we be checking to determine if the Intel Fortran runtime is already installed? We would like to have a registry key that we could check if possible.

Code doesn't compile after updating from XE2019 upd2 to upd4

$
0
0

I have a library which stopped compiling after updating from Parallel Studio XE2019 update 2 to Parallel Studio XE2019 update 4. I cheched it many times together with Visual Studio 2017 and updating to Visual Studio 2019 too and the result is always the same, the compilation gets stuck while compiling a particular file (always in the same file in a never ending process).

Has anyone noticed this same behavior? Has anyone reported any problem after updating? Any option different? I don't know.

Thanks.

Daniel.

snan initialization for allocatable arrays

$
0
0

Hi

Some time after this (https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-fo...) , IVF started to do NaN initial-value setting for allocatable arrays. 

The snippet below shows that allocatable arrays from type are not getting initialized. Is there anyway to do that?

The compile-line is: ifort /Od /debug:full /Qinit:snan /Qinit:arrays Test.f90

I am using Compiler 17.0 Update 4 with Visual Studio 2015.

Abhi

 

=====

      Module OM
         
         Implicit None
         
         Type newOBJ
            Integer :: j
            Real(8), Allocatable :: B(:)
         End Type newOBJ
         
      Contains
      
         Subroutine SetObject(This)
            
            Type(newOBJ), Intent(OUT) :: This
            
            Allocate(This%B(2)) ! This won't initialize to NaN
            
         End Subroutine
      
      End Module OM
   
      Program Test
         
         Use OM
         Implicit None
         
         Real(8), Allocatable :: A(:)

         Type(newOBJ) :: OBJ
         
         Allocate(A(3)) ! gets initialized to NaN
         !Allocate(OBJ%B(2)) ! OBJ%B will get initialized to NaN
         
         Call SetObject(OBJ)
         
      End Program Test

Code not converging, help

$
0
0

Hello, i'm a engineer student and never used fortran before. I'm  using it at a class, and we have to solve a 2D transient heat transfer problem. When I run my code, the solution does not converge. I think I am calculating the RMS wrong. Could you give me a hand?

 

 

DLL export with bind C

$
0
0

Dear Fortranners, consider the following function,

module Square_mod
    implicit none
contains
    function getSquare(val) result(valSquared) bind(C, name="getSquare")
        !DEC$ ATTRIBUTES DLLEXPORT :: getSquare
        use iso_c_binding
        use, intrinsic :: iso_fortran_env, only: RK => real64
        real(RK), intent(in) :: val
        real(RK)             :: valSquared
        valSquared = val ** 2
    end function getSquare
end module Square_mod

Now generating the DLL,

ifort /dll Square_mod.f90 /exe:Square

and here is a program that can successfully call the function in the DLL,

program Square_prog
    use, intrinsic :: iso_fortran_env, only: RK => real64
    use Square_mod, only: getSquare
    implicit none
    real(RK) :: val = 100._RK
    write(*,"(*(g0.13,:,''))") "Square of", val, "is", getSquare(val)
end program Square_prog

However, consider the following modified module that gives its function a different bind(c) name, getSq,

module Square_mod
    implicit none
contains
    function getSquare(val) result(valSquared) bind(C, name="getSq")
        !DEC$ ATTRIBUTES DLLEXPORT :: getSquare
        use iso_c_binding
        use, intrinsic :: iso_fortran_env, only: RK => real64
        real(RK), intent(in) :: val
        real(RK)             :: valSquared
        valSquared = val ** 2
    end function getSquare
end module Square_mod

Note that the only difference with the original function is in the binding name. I expected this function to be callable with the new name from the main program, but it is not,

program Square_prog
    use, intrinsic :: iso_fortran_env, only: RK => real64
    use Square_mod, only: getSq
    implicit none
    real(RK) :: val = 100._RK
    write(*,"(*(g0.13,:,''))") "Square of", val, "is", getSq(val)
end program Square_prog

Why is ifort able to "use Square_mod, only: getSquare" in the first version with a binding name that is the same as the function name, while in the latter case with a binding name different from the function name, it gives the following compile error?

Square_prog.f90(3): error #6580: Name in only-list does not exist or is not accessible.   [GETSQ]
    use Square_mod, only: getSq
--------------------------^
Square_prog.f90(6): error #6404: This name does not have a type, and must have an explicit type.   [GETSQ]
    write(*,"(*(g0.13,:,''))") "Square of", val, "is", getSq(val)
--------------------------------------------------------^
compilation aborted for Square_prog.f90 (code 1)

 


C# calls Fortran DLL calls MKL paradiso exited with code 2

$
0
0

Hello,

I have a C# Unit Test solution, which should test a *.dll created in Fortran. This *.dll is using the mkl library to solve an equation system. Unfortunately the paradiso call crashes. I made an minimal example with the paradiso example provided by Intel

C# Solution: UnitTestProjectMKL (DLLUsingMKL.dll, mkl_core.dll and mkl_sequential.dll are added as Link)

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Runtime.InteropServices;

namespace UnitTestProjectMKL
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            bool passed = false;
            NativeMethods.test_MKL_mod(ref passed);
            Assert.IsTrue(passed);
        }
    }


    public static class NativeMethods
    {
        [DllImport(@"DLLUsingMKL.dll ",
            EntryPoint = "MYMODULE_mp_TEST_MKL",
            CharSet = CharSet.Ansi,
            CallingConvention = CallingConvention.Cdecl)]
        public static extern void test_MKL_mod(ref bool passed);
    }
}

 

Fortran solution: DLLUsingMKL.sln

INCLUDE 'mkl_pardiso.f90'
MODULE myModule
  PUBLIC :: test_mkl
CONTAINS
  SUBROUTINE test_mkl(passed)
  !DEC$ ATTRIBUTES DLLEXPORT :: test_mkl
    USE mkl_pardiso
    IMPLICIT NONE
    
    LOGICAL(4), INTENT(INOUT), OPTIONAL :: passed
    
INTEGER, PARAMETER :: dp = KIND(1.0D0)
!.. Internal solver memory pointer 
TYPE(MKL_PARDISO_HANDLE), ALLOCATABLE  :: pt(:)
!.. All other variables
INTEGER maxfct, mnum, mtype, phase, n, nrhs, error, msglvl, nnz
INTEGER error1
INTEGER, ALLOCATABLE :: iparm( : )
INTEGER, ALLOCATABLE :: ia( : )
INTEGER, ALLOCATABLE :: ja( : )
REAL(KIND=DP), ALLOCATABLE :: a( : )
REAL(KIND=DP), ALLOCATABLE :: b( : )
REAL(KIND=DP), ALLOCATABLE :: x( : )
INTEGER i, idum(1)
REAL(KIND=DP) ddum(1)
!.. Fill all arrays containing matrix data.
n = 8 
nnz = 18
nrhs = 1 
maxfct = 1 
mnum = 1
ALLOCATE(ia(n + 1))
ia = (/ 1, 5, 8, 10, 12, 15, 17, 18, 19 /)
ALLOCATE(ja(nnz))
ja = (/ 1,    3,       6, 7,    &
           2, 3,    5,          &
              3,             8, &
                 4,       7,    &
                    5, 6, 7,    &
                       6,    8, &
                          7,    &
                             8 /)
ALLOCATE(a(nnz))
a = (/ 7.d0,        1.d0,             2.d0, 7.d0,        &
             -4.d0, 8.d0,       2.d0,                    &
                    1.d0,                         5.d0,  &
                          7.d0,             9.d0,        &
                                5.d0, 1.d0, 5.d0,        &
                                     -1.d0,       5.d0,  &
                                           11.d0,        &
                                                  5.d0 /)
ALLOCATE(b(n))
ALLOCATE(x(n))
!..
!.. Set up PARDISO control parameter
!..
ALLOCATE(iparm(64))

DO i = 1, 64
   iparm(i) = 0
END DO

iparm(1) = 1 ! no solver default
iparm(2) = 2 ! fill-in reordering from METIS
iparm(4) = 0 ! no iterative-direct algorithm
iparm(5) = 0 ! no user fill-in reducing permutation
iparm(6) = 0 ! =0 solution on the first n components of x
iparm(8) = 2 ! numbers of iterative refinement steps
iparm(10) = 13 ! perturb the pivot elements with 1E-13
iparm(11) = 1 ! use nonsymmetric permutation and scaling MPS
iparm(13) = 0 ! maximum weighted matching algorithm is switched-off (default for symmetric). Try iparm(13) = 1 in case of inappropriate accuracy
iparm(14) = 0 ! Output: number of perturbed pivots
iparm(18) = -1 ! Output: number of nonzeros in the factor LU
iparm(19) = -1 ! Output: Mflops for LU factorization
iparm(20) = 0 ! Output: Numbers of CG Iterations

error  = 0 ! initialize error flag
msglvl = 1 ! print statistical information
mtype  = -2 ! symmetric, indefinite

!.. Initialize the internal solver memory pointer. This is only
! necessary for the FIRST call of the PARDISO solver.

ALLOCATE (pt(64))
DO i = 1, 64
   pt(i)%DUMMY =  0 
END DO

!.. Reordering and Symbolic Factorization, This step also allocates
! all memory that is necessary for the factorization

phase = 11 ! only reordering and symbolic factorization

CALL pardiso (pt, maxfct, mnum, mtype, phase, n, a, ia, ja, &
              idum, 0, iparm, msglvl, ddum, ddum, error)
    
WRITE(*,*) 'Reordering completed ... '
IF (error /= 0) THEN
   WRITE(*,*) 'The following ERROR was detected: ', error
   GOTO 1000
END IF
WRITE(*,*) 'Number of nonzeros in factors = ',iparm(18)
WRITE(*,*) 'Number of factorization MFLOPS = ',iparm(19)

!.. Factorization.
phase = 22 ! only factorization
CALL pardiso (pt, maxfct, mnum, mtype, phase, n, a, ia, ja, &
              idum, nrhs, iparm, msglvl, ddum, ddum, error)
WRITE(*,*) 'Factorization completed ... '
IF (error /= 0) THEN
   WRITE(*,*) 'The following ERROR was detected: ', error
   GOTO 1000
ENDIF

!.. Back substitution and iterative refinement
iparm(8) = 2 ! max numbers of iterative refinement steps
phase = 33 ! only solving
DO i = 1, n
   b(i) = 1.d0
END DO
CALL pardiso (pt, maxfct, mnum, mtype, phase, n, a, ia, ja, &
              idum, nrhs, iparm, msglvl, b, x, error)
WRITE(*,*) 'Solve completed ... '
IF (error /= 0) THEN
   WRITE(*,*) 'The following ERROR was detected: ', error
   GOTO 1000
ENDIF
WRITE(*,*) 'The solution of the system is '
DO i = 1, n
   WRITE(*,*) ' x(',i,') = ', x(i)
END DO
      
1000 CONTINUE
!.. Termination and release of memory
phase = -1 ! release internal memory
CALL pardiso (pt, maxfct, mnum, mtype, phase, n, ddum, idum, idum, &
              idum, nrhs, iparm, msglvl, ddum, ddum, error1)

IF (ALLOCATED(ia))      DEALLOCATE(ia)
IF (ALLOCATED(ja))      DEALLOCATE(ja)
IF (ALLOCATED(a))       DEALLOCATE(a)
IF (ALLOCATED(b))       DEALLOCATE(b)
IF (ALLOCATED(x))       DEALLOCATE(x)
IF (ALLOCATED(iparm))   DEALLOCATE(iparm)

IF (error1 /= 0) THEN
   WRITE(*,*) 'The following ERROR on release stage was detected: ', error1
   STOP 1
ENDIF

IF (error /= 0) STOP 1
  END SUBROUTINE test_mkl
END MODULE myModule

 

/nologo /debug:full /Od /Qopenmp_stubs /warn:interfaces /module:"Debug\\" /object:"Debug\\" /Fd"Debug\vc160.pdb" /traceback /check:bounds /check:stack /libs:dll /threads /Qmkl:sequential /c

 

The Output is not giving me much clue where to look for the error

'testhost.x86.exe' (Win32): Loaded 'D:\...\BugMinimalFortranUTestMKL\UnitTestProjectMKL\bin\Debug\mkl_core.dll'. Module was built without symbols.
'testhost.x86.exe' (Win32): Unloaded 'D:\...\BugMinimalFortranUTestMKL\UnitTestProjectMKL\bin\Debug\mkl_core.dll'
'testhost.x86.exe' (Win32): Loaded 'D:\...\BugMinimalFortranUTestMKL\UnitTestProjectMKL\bin\Debug\mkl_core.dll'. Module was built without symbols.
'testhost.x86.exe' (Win32): Loaded 'C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\mpirt\libimalloc.dll'. 
'testhost.x86.exe' (Win32): Unloaded 'C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\mpirt\libimalloc.dll'
'testhost.x86.exe' (Win32): Loaded 'C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\mpirt\libimalloc.dll'. 
'testhost.x86.exe' (Win32): Unloaded 'C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\mpirt\libimalloc.dll'
The thread 0x5494 has exited with code 2 (0x2).
The thread 0x5444 has exited with code 2 (0x2).
The thread 0x7cbc has exited with code 2 (0x2).
The thread 0x3304 has exited with code 2 (0x2).
The thread 0x60cc has exited with code 2 (0x2).
The thread 0x27b0 has exited with code 2 (0x2).
The thread 0xa74 has exited with code 2 (0x2).
The thread 0x4ec4 has exited with code 2 (0x2).
The thread 0x620c has exited with code 2 (0x2).
The thread 0x4108 has exited with code 2 (0x2).
The thread 0x7038 has exited with code 2 (0x2).
The thread 0x360c has exited with code 2 (0x2).
The thread 0x2538 has exited with code 2 (0x2).
The thread 0x52b4 has exited with code 2 (0x2).
The thread 0x3ee0 has exited with code 2 (0x2).
The thread 0x1e4c has exited with code 2 (0x2).
The thread 0x528 has exited with code 2 (0x2).
The thread 0x11bc has exited with code 2 (0x2).
The thread 0x68ac has exited with code 2 (0x2).
The thread 0x74e4 has exited with code 2 (0x2).
The thread 0x22b8 has exited with code 2 (0x2).
The thread 0x27d0 has exited with code 2 (0x2).
The program '[6832] testhost.x86.exe' has exited with code 2 (0x2).

 

I would be happy if someone could point me in the right direction.

Input line too long error when running Windows batch file

$
0
0

When running an IVF project through a Windows batch file through a regular command prompt i.e. not the one provided by the Intel compiler, an error periodically shows up with the message "Input line too long". Is this Windows or IVF related? 

The batch files always begin by setting the correct environment ex.

call "%IFORT_COMPILER19%bin\ipsxe-comp-vars.bat" ia32 vs2017

Some characteristics of the error (when it appears) are:

1. Occurs when the batch file is repeatedly executed in the same command window.

2. Disappears when the command window is closed and restarted.

3. Could the repeated call to the ipsxe-comp-vars.bat be the problem?

function that returns 0-bound array converts it do a 1-bound array.

$
0
0

I have a function that initializes a 0-bound array of a custom type. This is for a simulation, and the function returns an array of results, with the first item (0 index) being the initial conditions.

    function model3_run(this, end_time, steps) result(sol)
    class(model3), intent(inout) :: this
    real(8), intent(in) :: end_time
    integer, intent(in) :: steps    
    type(state3), allocatable :: sol(:)
    real(8) :: time_step
    integer :: i
        allocate(sol(0:steps))  !  allocate the 0-bound array
        sol(0) = this%initial_state
        time_step = end_time / steps
        do i=1,steps
            sol(i) = this%step(sol(i-1), time_step)
        end do
    end function

when I use `lbound(sol)` and `ubound(sol)` here I get the expected results.

Now the main program runs this code, and stores the results in an allocatable array.

    type(model3) :: sim
    type(state3), allocatable :: solution(:)

        solution = sim%run(0.1d0, 10)        

The problem is that `solution` is no longer a 0-bound array. The first element is stored in index=1.

 

So my question is as follows: if I am doing it wrong, what is the correct way to allocate a 0-bound dynamic array in a function an use it outside from the main program?

passing string from Fortran to C

$
0
0

Consider the following Fortran function,

module String_mod
    use, intrinsic :: iso_fortran_env, only: IK => int32
    implicit none
contains
    function getLowerCase(StrVec) result(StrVecLowerCase) bind(C, name="getLowerCase")
        character(len=*), intent(in)    :: StrVec
        integer(IK), parameter          :: duc = ichar('A') - ichar('a')
        character(len=1)                :: StrVecLowerCase
        character                       :: ch
        integer(IK)                     :: lenStrVec
        integer(IK)                     :: i
        lenStrVec = len(StrVec)
        write(*,"(*(g0))") "From Inside Fortran@getLowerCase(): StrVec = ", (StrVec(i:i),i=1,lenStrVec)
        do i = 1, lenStrVec - 1
            ch = StrVec(i:i)
            if (ch>='A' .and. ch<='Z') ch = char(ichar(ch)-duc)
            !StrVecLowerCase(i:i) = ch
        end do
        StrVecLowerCase = "S"
    end function getLowerCase
end module String_mod

which can take a string from C, and ideally convert it to lower case and send it back to C as the function ouput. I have managed to send a string from C to Fortran with the following C code,

#include "ISO_Fortran_binding.h"
#include <string.h>
extern char* getLowerCase(CFI_cdesc_t *);
int main()
{
    char *StrVec = "This is a C string";

    // Initialize the C descriptor as a scalar character nonpointer
    CFI_cdesc_t StrVecDesc;
    int retval = CFI_establish(&StrVecDesc, StrVec, CFI_attribute_other, CFI_type_char, strlen(StrVec), 0, NULL);

    // Call getLowerCase
    char *success = getLowerCase(&StrVecDesc);
    printf("%s", &success);
    return 0;
}

However, I am not sure at the moment what the best approach would be according to Fortran-2018 to return a string (not a single character) from Fortran to C as the function output. Any help is appreciated.

 

Make a static property shared between all instances of a class

$
0
0

Is it possible to define a static property that is shared between all instances of a class?

The case is a element class which uses a vector class.

I want that all element objects have a vector_i and vector_j which define the global normal vectors (i.e vector_i = vector(1, 0, 0) and vector_j = vector(0, 1, 0)).

Viewing all 5691 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>