Gillee

222 Reputation

8 Badges

6 years, 240 days

MaplePrimes Activity


These are questions asked by Gillee

I have entered a few examples from the Maple Example Worksheets on the the topic of using compiled Fortran code. I got two simple examples to work as shown in my worksheet below. The third example was to perform a matrix multiplication and that is where I get the "Error, (in fmat_mult) unhandled return type". Could you point out my mistake? Thank you in advance.

Using compiled FORTRAN code:

 

1) write a FORTRAN function in Geany

2) compile it to an object file *.o

2) open terminal in the folder where the file is saved

3) generate a *.dll file by: gfortran -shared -o mult.dll mult.o

4) setup the call to your functions: see lines fmult:= define_external( ) and fmultf:= define_external( ).

 

restart:
kernelopts(version);

`Maple 2023.2, X86 64 WINDOWS, Nov 24 2023, Build ID 1762575`

(1)

 

Multiply two integers

 

fmult:=define_external('mult', LIB= "C:/Users/familee/OneDrive/Documents/Maple/DLL-example/mult.dll", FORTRAN, 'a'::(integer[4]), 'b'::(integer[4]), RETURN::(integer[4]))

(2)

 

Multiply two floating point numbers

 

fmultf:=define_external('multf', LIB= "C:/Users/familee/OneDrive/Documents/Maple/DLL-example/multf.dll", FORTRAN, 'a'::(float[8]), 'b'::(float[8]), RETURN::(float[8]))

fmult(10,3)

30

(3)

fmultf(10.1,3.3)

33.3299999999999983

(4)

fmultf(100.234,67.901)

6805.98883399999886

(5)

 

Matrix multiplication example

 

a:=Matrix([[1.,4.,7.],[2.,5.,8.],[3.,6.,9.]],datatype=float[8],order=Fortran_order);

Matrix(3, 3, {(1, 1) = 1.0, (1, 2) = 4.0, (1, 3) = 7.0, (2, 1) = 2.0, (2, 2) = 5.0, (2, 3) = 8.0, (3, 1) = 3.0, (3, 2) = 6.0, (3, 3) = 9.0})

(6)

b:=Matrix([[1.,4.,7.],[2.,5.,8.],[3.,6.,9.]],datatype=float[8],order=Fortran_order);

Matrix(3, 3, {(1, 1) = 1.0, (1, 2) = 4.0, (1, 3) = 7.0, (2, 1) = 2.0, (2, 2) = 5.0, (2, 3) = 8.0, (3, 1) = 3.0, (3, 2) = 6.0, (3, 3) = 9.0})

(7)

c:=Matrix(1 .. 3, 1 .. 3, fill = 0.,datatype=float[8],order=Fortran_order);

Matrix(3, 3, {(1, 1) = 0., (1, 2) = 0., (1, 3) = 0., (2, 1) = 0., (2, 2) = 0., (2, 3) = 0., (3, 1) = 0., (3, 2) = 0., (3, 3) = 0.})

(8)

a.b

Matrix(3, 3, {(1, 1) = 30.0, (1, 2) = 66.0, (1, 3) = 102.0, (2, 1) = 36.0, (2, 2) = 81.0, (2, 3) = 126.0, (3, 1) = 42.0, (3, 2) = 96.0, (3, 3) = 150.0})

(9)

 

Is it possible to use a subroutine to pass a matrix?

 

mat_mult,f subroutine returns c = a.b

 

FORTRAN code for mat_mult.f

 

       SUBROUTINE mat_mult(a,b,c,m,n)  
C
C      Compute matrix multiplication.
C
       INTEGER i,j,k
       INTEGER m,n
       
       REAL*8 tmp
C      m rows by n cols
       REAL*8 a(m,n)
       REAL*8 b(m,n)
       REAL*8, intent (out)::c(m,n)
C      m = n
       DO 11 j=1,n
         DO 12 i=1,n
            tmp = 0.0
            DO 13 k=1,n
               tmp = tmp + a(i,k) * b(k,j)
 13         CONTINUE
            c(i,j) = tmp
 12      CONTINUE
 11    CONTINUE
       RETURN
       END

Compiled to get the object file: mat_mult.o

Generate a dll: gfortran -shared -o mat_mult.dll mat_mult.o

 

fmat_mult:=define_external( 'mat_mult', LIB= "C:/Users/familee/OneDrive/Documents/Maple/DLL-example/mat_mult.dll", FORTRAN, 'a'::(ARRAY(datatype=float[8])), 'b'::(ARRAY(datatype=float[8])), 'c'::(ARRAY(datatype=float[8])), 'm'::(integer[4]), 'n'::(integer[4]), RETURN::(ARRAY(datatype=float[8])) )

(10)

 

The results should be the Matrix c

 

fmat_mult(a,b,c,3,3)

Error, (in fmat_mult) unhandled return type

 

 

mult-Fortran_dll.mw

 

I made the upgrade to Maple 2023 today and for fun I compiled a simple procedure. I got an error in Maple 2023. So I ran the same lines of code in Maple 2022 and eveything works. Does anyone sees this problem?

restart:
kernelopts(version);

`Maple 2023.0, X86 64 WINDOWS, Mar 06 2023, Build ID 1689885`

(1)

p := proc( x :: float ) :: float; 2.3 * x end proc:

cp:=Compiler:-Compile(p)

Error, (in Compiler:-Compile) linker exited with nonzero status 1:

 

cp(1.1)

cp(1.1)

(2)

 

Download compile_ex.mw

Hi Everyone,

I would like to convert a netlist to a ladder schematic by using Draw (Syrup). So far I have tried combinations of &+ and &// and have not achieved the correct result. Please help.

capnet:= "
V  1 0 1
L  1 2 1
C1 2 3 2uF 
C2 2 4 3uF
C3 4 3 1uF
C4 4 5 1.5uF
C5 3 5 2.5uF
C6 3 0 3.5uF
C7 5 0 0.5uF
.end":

ckt:= [ V(1), L(1), C1(2.8E-6),
         C2(3.E-6),  C3(1.E-6),
         C4(1.5E-6), C5(2.5E-6) &+ C6(3.5E-6)
        ]:
Draw(ckt);

Thanks.

SyrupQuestion.mw

Hi Maple Users,

Microsoft is enticing me to upgrade to Windows 11 from 10 for free. I am a bit hesitant because I don't know if Maple 2021 will continue working as well as in Windows 10. Does anyone have any thoughts or wisdom to share.

Thank you.

Hi,

Is there a way to change the font type and size when printing a table of data using DocumentTools:-Tabulate? Also can I change the column width?

DocTabFont.mw

1 2 3 4 Page 1 of 4