## How to multithread to aid with constructing a list...

I'm trying to write some simple code to help plot an approximation of a solution to the heat equation. On one set of axes I want to plot the temperature characteristic of a 1-D bar at different temperatures. I am able to do this easily enough, but the code uses a for loop and my core i7 is not being utilized properly. To rectify this I have tried to use threads, but after many hours of playing around I cannot get it to work fully. The first time I run my code I am faced with the error "Error, (in plot) cannot determine if this expression is true or false: not fHwLibraryInitialized".

Then after this I can run my code a few more times and it will produce a graph, but each time the graph will be different, meaning most of them are incorrect. After running my display command several times I am then faced with the error "kernel connection has been lost", and I need to restary. I have never played with threads before and have very little understanding of how it works.

```with(Threads);
with(plots);

para := proc (A, B)
return [op(A), op(B)];
end proc;

HeatP := proc (f, g, n, lambda, X, N, M, T)
local k, u, i, L, a;
u := proc (x, t) options operator, arrow; sum((int(sin(k*lambda*x)*g, x = 0 .. 1))*exp(-k*lambda*t)*sin(k*lambda*x), k = 1 .. n) end proc;
L := [];
if N-X < 3 then for i from X to N do
L := [op(L), plot(u(x, (i*T-T)/M), x = 0 .. 1)]
end do;
return L;
else a := floor((1/2)*(N-X))+X;
Threads:-Task:-Continue(para, Task = [HeatP, f, g, n, lambda, X, a, M, T], Task = [HeatP, f, g, n, lambda, a+1, N, M, T])
end if
end proc;

g := piecewise(x <= 0, 0, 0 < x and x < 1, exp(-2/(1-(x-1/2)^2)), x >= 0, 0);

```

I cannot see where the problem is, but there is obviously at least one. Any help would be appreciated.

I'm running calculations like this:

N:=10000;
f := (i,j)-> (some complicated procedure depending on i and j);

I have a server with 20 cores, but each core has two threads, so this code should max out all 40 threads. But what I notice is only at most 20 threads being used at a time.

I checked kernelopts(numcpus) returns 20.

Does anyone have any advice on how to maximize my resource usage?

Hi!I am running some grid computations and I found that I could speed up my computations if my nodes could share some partial results. It seems that Grid:-Send and Grid:-Receive is almost perfect. The problem is that Grid:-Receive blocks the computations where I cannot ensure that a message will ever be send. I've tried to run Grid:-Receive on a thread in an possible infinite loop but it still blocks.

Some pieces of code below:

SignatureReciever:=proc(SigContainer::uneval,stopValue::uneval)
while eval(stopValue) do
end do;
end proc:

SendMessage:=proc(message::string, id::integer)
Threads[Seq](proc(i) if i <> id then Grid:-Send(i,message) end if end proc,i=0..Grid:-NumNodes()-1);
end proc:

In the main procedure run on a node I have

....

....

SendMessage(signature,id);

....

....

stopValue := false;

Do you have any suggestions how to solve my problem?

Hi!

I have a problem recently with running RootFinding:-Isolate inside a procedure which is run on threads. I have many polynomial systems to treat so I would like to balance computations between cores. Unfortunately, my code always breaks computation kernel with the error:

java.lang.NullPointerException

at com.maplesoft.mathdoc.model.WmiModelLock.acquireLock(Unknown Source)
at com.maplesoft.mathdoc.model.WmiModelLock.writeLock(Unknown Source)

I wrote a small example below

f:=proc(n)

local i;

for i from 1 to n do
try

RootFinding:-Isolate([a^2+b^2-1/3c^2,a^2-1/3b^2+c^2-1/3,a^2-1/3b^2-1/3c^2+1],[a,b,c]):

catch "":
next:
end try:
end do:
end proc:

I have no much of experiences with threads in Maple so I would not be surprise if I'm trying to do something completely wrong here. Any hint or advice will be appreciate.

## Increasing CPU usage...

Hi

When I run a maple file it uses 25% of CPU.

When I run 2 files, the half of CPU is used.

How can I change the preferences for using most of CPU