Question:Why does Threads:-Map return a different result in this situation?

Question:Why does Threads:-Map return a different result in this situation?

Maple 2020

Hello

I am trying to use Threads in my procedures as much as possible.  However, one of them returned different results when compared to map or Grid:-Map (I have checked if the used functions are threadsafe (perhaps I miss something)).  Here is the procedure (optimization of the code is most welcome).

```searchMonomialsEqns:=proc(conds::set,Eqns::list,Vars::list,poolofeqns::list(list))
description "Find if a set of monomials in an equation can be found in a pool of monomials and returns the condition when it is true":
local A:=Array(1..0),
C,
i,
res,
n:=numelems(Eqns):
#  Find the monomials of Eqns
res:=subs(conds,Eqns):
for i from 1 to n do
C:= coeffs(expand(lhs(res[i])-rhs(res[i])),Vars, 'M'):
A,={M}:
end do:
ifelse(member([seq(A)],poolofeqns)=false,NULL,conds):
end proc:
```

`ans1:=CodeTools:-Usage(Threads:-Map(w->searchMonomialsEqns(w,eqns[1..2],vars[2..3],validYZeqnMon),conds5)):nops(ans1);`

returns

memory used=0.58GiB, alloc change=139.56MiB, cpu time=40.23s, real time=11.12s, gc time=1.01s

8613

2) map

`ans2:=CodeTools:-Usage(map(w->searchMonomialsEqns(w,eqns[1..2],vars[2..3],validYZeqnMon),conds5)):nops(ans2);`

returns

memory used=0.57GiB, alloc change=-4.00MiB, cpu time=22.48s, real time=21.55s, gc time=1.70s

8637

3) Grid:-Map

`ans3:=CodeTools:-Usage(Grid:-Map(w->searchMonomialsEqns(w,eqns[1..2],vars[2..3],validYZeqnMon),conds5)):nops(ans3);`

return

memory used=23.29MiB, alloc change=21.88MiB, cpu time=3.77s, real time=2.25s, gc time=3.14s

8637

Although the number of elements is the same, Grid:-Map returns the result with set function mentioned in my previous post. (I am aware that CodeTools:-Usage is pointless here).

```ans4:=CodeTools:-Usage([Threads:-Seq](searchMonomialsEqns(conds5[i],eqns[1..2],vars[2..3],validYZeqnMon),i=1..nops(conds5))):nops(ans4);
```

returns

memory used=0.58GiB, alloc change=0 bytes, cpu time=33.99s, real time=8.68s, gc time=644.74ms

8622

What am I missing?

Many thanks

Ed

﻿