Items tagged with compiler

Feed

I was trying to answer a question by torabi 25, August 14, 2017 to speed up his calculations. I got this idea of converting the original code to a procedure - that was not easy, run the procedure and obtain a value of time() to establish a baseline, and making sure the answer from the procedure was the same as from torabi 25. So far so good. Then I would compile the procedure, execute it, and get another value for time(). Hopefully the compiled procedure will be faster than the uncompiled procedure. I am close, but - please see if you can fix my compiler error. Thanks!


 

restart

pa := proc (k::integer, h::float, N::float, nu::float, E_m::float, E_c::float, rho_m::float, rho_c::float, d::(Matrix()))::float; local lambda_m::float, lambda_c::float, mu_m::float, mu_c::float, Z::float, U::float, S::float, e2::float, f::float, W::float, z::float, b::integer, alpha::integer, beta::integer; lambda_m := nu*E_m/((1+nu)*(1-2*nu)); lambda_c := nu*E_c/((1+nu)*(1-2*nu)); mu_m := E_m/(2+2*nu); mu_c := E_c/(2+2*nu); Z := rho_m+(rho_c-rho_m)*(1/2+z/h)^N; U := lambda_m+(lambda_c-lambda_m)*(1/2+z/h)^N; S := mu_m+(mu_c-mu_m)*(1/2+z/h)^N; e2 := 0.; for alpha from 0 to k-2 do for b from 0 to k-2 do for beta from 0 to k-1 do f := 2*S*d[beta+1, alpha+1]*W(beta)*sqrt(alpha+1/2)*orthopoly:-P(alpha, z)*d[2, b+1]*sqrt(b+1/2)*orthopoly:-P(b, z); e2 := e2-(int(f, z = -(1/2)*h .. (1/2)*h)) end do end do end do end proc

NULL

k := 6; h := 1.; N := .5; nu := .3; E_m := 7.0*10^10; E_c := 3.80*10^11; rho_m := 2702.; rho_c := 3800.; d := Matrix([evalf([0, 0, 0, 0, 0, 0, 0, 0]), evalf([sqrt(3), 0, 0, 0, 0, 0, 0, 0]), evalf([0, sqrt(15), 0, 0, 0, 0, 0, 0]), evalf([sqrt(7), 0, sqrt(35), 0, 0, 0, 0, 0]), evalf([0, sqrt(27), 0, sqrt(63), 0, 0, 0, 0]), evalf([sqrt(11), 0, sqrt(55), 0, sqrt(99), 0, 0, 0]), evalf([0, sqrt(39), 0, sqrt(91), 0, sqrt(143), 0, 0]), evalf([sqrt(15), 0, sqrt(75), 0, sqrt(135), 0, sqrt(195), 0])], datatype = float[8])

time(pa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d))

2.156

(1)

pa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d)

-0.3192307695e12*W(1)+0.4396880666e12*W(3)-0.1474586302e12*W(5)-0.9235575679e11*W(2)+0.1979090107e12*W(4)

(2)

# Original Answer:        -3.192307692*10^11*W(1)+4.396880662*10^11*W(3)-1.474586301*10^11*W(5)-9.235575669*10^10*W(2)+1.979090105*10^11*W(4);NULL

cpa := Compiler:-Compile(pa)

Error, (in Compiler:-Compile) Array parameter types must specify a hardware datatype

 

time(cpa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d))

0.

(3)

cpa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d)

NULL


 

Download for_(5).mw

 

Why won't this procedure Compile? All I get is a cryptic and ungrammatical error message.

    step:= proc(
          n::integer[4],
          XYZ::Matrix(datatype= float[8]),
          E::Vector(datatype=integer[4]), F::Vector(datatype=integer[4]),
          W::Matrix(datatype= float[8]), #3x2 scratch matrix
          mu::integer[4]
     )
     option autocompile;
     local
          i::integer[4], j::integer[4],
          ed::float[8],
          fd::float[8],
          p::float[8], t::float[8]       
     ;
          to mu do
               for i to n do
                    ed:= 0;  fd:= 0;
                    for j to 3 do
                          p:= XYZ[i,j];
                          t:= XYZ[E[i],j] - p;
                          ed:= ed+t^2;
                          W[j,1]:= t;
                          t:= XYZ[F[i],j] - p;
                          fd:= fd+t^2;
                          W[j,2]:= t
                    od;
                    ed:= sqrt(ed) + .01;  fd:= sqrt(fd) + .01;
                    for j to 3 do
                         XYZ[i,j]:= 0.995*XYZ[i,j] - 0.01*W[j,1]/ed + 0.02*W[j,2]/fd
                    od
               od
          od
     end proc;
Compiler:-Compile(step);

Error, (in Compiler:-Compile1) In memory compilation failed

I am trying to use Compiler:-Compile with a generated function having a Vector as an argument. My function is (in a simplified form)

Mapt:=proc (pv) options operator, arrow; rtable(1 .. 6, {1 = .998026692438229*pv[1]-.605526643146912*pv[2]+0.154549004943741e-1*pv[6]+0.140818440886566e-5*pv[5], 2 = 0.651134546344795e-2*pv[1]+.998026692438228*pv[2]-0.510903331894809e-1*pv[6]+0.229399145141077e-8*pv[5], 3 = -.500000000000002*pv[3]-5.95856898901206*pv[4], 4 = .125869147673385*pv[3]-.499999999999996*pv[4], 5 = 0.510903331894806e-1*pv[1]-0.154549004943901e-1*pv[2]-40.6778361021594*pv[6]+.999998210424947*pv[5], 6 = .999998210424947*pv[6]-0.229399145141220e-8*pv[1]-0.140818440886565e-5*pv[2]+0.897571581395136e-7*pv[5]}, datatype = anything, subtype = Vector[column], storage = rectangular, order = Fortran_order) end proc;

Since this returns a Vector it cannot be compiled as is. So I split off the first output element (with the idea to later on do this with the others as well):

xpr:=eval(Mapt(<pv[1],pv[2],pv[3],pv[4],pv[5],pv[6]>))[1];
f1:=unapply(xpr,pv);
f1(<0.001,0.001,0,0,0,0>); # test f1: works
          0.000392500049291317

sf1:=Compiler:-Compile(f1); # this works, too

sf1(<0.001,0.001,0,0,0,0>); # but this fails
Error, (in sf1) invalid input: expecting a hardware float[8] rtable, but received 1


The examples in the Helpfile run so I think my installation is ok (my old Maple 15 won't even run the examples, but that is a different story). I have been banging my head against the wall here, trying many different ways, but none of them successfull. Worse, I do not understand the error message at all. Test program attached.

Mac OS X 10.10.5

Thanks for any hint,

M.D.

Compiler.mw

What is the correct mode of using dsolve/numeric/compile with Grid package?

I've tried a lot of different, but only one turned out to be working is by using Grid:-Seq(dsolve..., i=1).

For example:

...

dsol := Grid:-Seq(dsolve(dsys, numeric, parameters = [bb, qq, prf0, `p&theta;f0`], compile = true, optimize = true, output = listprocedure, maxfun = 0), i = 1):

dsol3 := proc (tt) try dsol[3](tt) catch "cannot evaluate the solution further": tt = 0. end try end proc:

st := time[real]():

A := Array([Grid:-Seq([seq(op(2, [dsol[1](parameters = [b[i, j], q[i, j], pr[i, j], `p&theta;`[i, j]]), rhs(dsol3(-10^6))]), j = 1 .. sz[2])], i = 1 .. sz[1])]);

time[real]()-st;

example.mw

But this mode not stable and causing to this error very often:

Error, (in dsolve/numeric/SC/preproc) unable to post-link (rc=31), please try again, and if that fails check that your Windows SDK installation is up to date, and compatible with your Windows compiler

How I can fix this problem?

Dear all,

I want to use the Maple Compiler to improve the performance of some of my codes. To get used to it, I tried doing the examples from the ?Compiler help-page, but everytime I run the compiler, I get the error message:

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

Do some of you know a possible reason for this?

Thank you all.

Download test.mw

The following (downsized) images of Lyapunov fractals were each generated in a few seconds, in Maple 16.

 

I may make an interface for this with embedded components, or submit it in some form on the Application Center. But I thought that I'd share this version here first.

I'm just re-using the techniques in the code behind an earlier Post on Mandelbrot and Julia fractals. But I've only used one simple coloring scheme here, so far. I'll probably try the so-called burning ship escape-time fractal next.

 

 

 

 

Here below is the contents of the worksheet attached at the end of this Post.

 

 

The procedures are defined in the Startup code region of this worksheet.

 

It should run in Maple 15 and 16, but may not work in earlier versions since it relies on a properly functioning Threads:-Task.

 

The procedure `Lyapunov` can be called as

 

          Lyapunov(W, xa, xb, ya, yb, xresolution)

          Lyapunov(W, xa, xb, ya, yb, xresolution, numterms=N)

 

where those parameters are,

 

 - W, a Vector or list whose entries should be only 0 or 1

 - xa, the leftmost x-point (a float, usually greater than 2.0)

 - xb, the rightmost x-point (a float, usually less than or equal to 4.0)

 - ya, the lowest y-point (a float, usually greater than 2.0)

 - yb, the highest y-point (a float, usually less than or equal to 4.0)

 - xresolution, the width in pixels of the returned image (Array)

 - numterms=N, (optional) where positive integer N is the number of terms added for the approx. Lyapunov exponent

 

 

The speed of calculation depends on whether the Compiler  is functional and how many cores are detected. On a 4-core Intel i7 under Windows 7 the first example below had approximately the following performce in 64bit Maple 16.

 

 

Compiled

evalhf

serial (1 core)

20 seconds

240 seconds

parallel (4 cores)

5 seconds

60 seconds

 

 

 

with(ImageTools):


W:=[0,0,1,0,1]:
res1:=CodeTools:-Usage( Lyapunov(W, 2.01, 4.0, 2.01, 4.0, 500) ):

memory used=46.36MiB, alloc change=65.73MiB, cpu time=33.87s, real time=5.17s


View(res1);


W:=[1,1,1,1,1,1,0,0,0,0,0,0]:
res2:=CodeTools:-Usage( Lyapunov(W, 2.5, 3.4, 3.4, 4.0, 500) ):

memory used=30.94MiB, alloc change=0 bytes, cpu time=21.32s, real time=3.54s


View(res2);


W:=[1,0,1,0,1,1,0,1]:
res3:=CodeTools:-Usage( Lyapunov(W, 2.1, 3.7, 3.1, 4.0, 500) ):

memory used=26.18MiB, alloc change=15.09MiB, cpu time=18.44s, real time=2.95s


View(res3);


W:=[0,1]:
res4:=CodeTools:-Usage( Lyapunov(W, 2.01, 4.0, 2.01, 4.0, 500) ):

memory used=46.25MiB, alloc change=15.09MiB, cpu time=33.52s, real time=5.18s


View(res4);

 

 

Download lyapfractpost.mw

I installed M16 32 Bit on my new machine with Win7 64 Bit.

But the following results in crushing mserver.exe:

  tmp := proc( x :: float ) :: float; 2.3 * x end proc:
  cp:=Compiler:-Compile(tmp);

with system info below.

Do I have to set certain rights for the compiler or define a specific working directory?

The FAQ http://www.maplesoft.com/support/faqs/results.aspx?search=compiler does not help me.

Dito http://www.maplesoft...

ggg:=(y,a,b)->
(2*(-a+6*y^2*a^2+2*b*y^2*a^2+9*b*y^3*a+3*b*y^2*a+b*y^6*a^2+4*b*y^5*a^2+5*b*y^4*a^2+2*b*y^5*a+8*b*y^4*a+3*b*y^3*a^2+4*b*y^2-y^3*a-3*y^2*a+y^6*a^3+5*y^5*a^3+8*y^4*a^3+4*y^3*a^3+y^5*a^2+5*y^4*a^2+9*y^3*a^2+b*y^4+4*b*y^3+y*a^2+2*a*b*y+y^3*a*(y+1)^(-2*b)+a*(y+1)^(-2*b)+3*y^2*a*(y+1)^(-2*b)+3*y*a*(y+1)^(-2*b)-2*y^2*a^2*(y+1)^(-2*b)-y*a^2*(y+1)^(-2*b)-3*y*a-y^3*a^2*(y+1)^(-2*b))/(y^2*(a+b)*(y+1)*(y+2)^2*(y*a+1)^2)+(-2-y^2+2*y^2*a^2-2*y+4*b*y^3*a+8*b*y^2*a+2*b*y^4*a^2+4*b*y^3*a^2...

I just downloaded Maple 15 and am trying to install on a 64-bit Windows 7 machine.

 

About halfway through the installation, there is a step where you are either supposed to supply the path to a batch file that will supply the environment variables that will locate Microsoft Visual C compiler, or supply them later as an option. The instructions say that Maple has a default batch file that will do this, but when that option is chosen, nothing shows up in...

Dear Maple lovers,

As a classical worksheet user from the past years, now I'd like to be a "modern" Maple user, using the 2D Input in the modern worksheet mode (I will call it mwm from now on). But, alas, I cannot even solve a simple equation!

To describe my situation let me state the following:

1. I use 64 bit Maple 14 Student Edition (single user) under 64 bit Windows 7.

2....

There are two pieces of extended functionality that I quite often want from the Maple Compiler. The first (task A) is to be able to link in and use an arbitrary function from some other external ("3rd party") shared library, within my Compile'd Maple procedure. The second (task B) is to directly call the compiled Maple procedure from within some computational routine in a 3rd party shared library (which I would then access using define_external). This post is about the first of those, task A.

Page 1 of 1