# Overhead of concurrent\_maplist

**URL:** <https://swi-prolog.discourse.group/t/overhead-of-concurrent-maplist/6440>\
**Category:** General\
**Created:** [April 5, 2023, 3:05pm UTC](https://swi-prolog.discourse.group/t/overhead-of-concurrent-maplist/6440 "2023-04-05T15:05:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximilianocristia](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/maximilianocristia/32/5377_2.png) [@maximilianocristia](https://swi-prolog.discourse.group/u/maximilianocristia)\
**Post date:** [April 5, 2023, 3:05pm UTC](https://swi-prolog.discourse.group/t/overhead-of-concurrent-maplist/6440/1 "2023-04-05T15:05:42Z")

</div>

Hi!

The manual page of `concurrent_maplist` says:

> Note that the the overhead of this predicate is considerable and therefore Goal must be fairly expensive before one reaches a speedup.

What do you mean with “considerable” and “fairly expensive”?

We have goals that take from 60 to 110 seconds when executed sequentially. Are these fairly expensive to be run concurrently using `concurrent_maplist`?

I mean, say `p(x)` takes 60 seconds to complete and `p(y)` takes 110 seconds, if I do:

`concurrent_maplist(p,[x,y])`

would it take nearly 110 seconds to finish (in a two or more core machine)?

I guess it should but maybe the overhead of `concurrent_maplist` is much higher than I think.

Is it possible that it takes 120 (i.e. the overhead is around 10 second for a 2 element list)? If I have an 8 element list of goals taking from 60 to 230, is it possible that `concurrent_maplist` takes around 400 seconds in a 8 core machine?

Thanks in advance!

Maxi

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [April 5, 2023, 4:05pm UTC](https://swi-prolog.discourse.group/t/overhead-of-concurrent-maplist/6440/2 "2023-04-05T16:05:48Z")

</div>

Here’s the overhead for concurrent\_maplist/2 with 100 and 1000 items on my 4-core machine:

```prolog
[user].
|: m(Xs,X) :- member(X,Xs).
|: 

```

```prolog
?- findall(X,between(1,100,X),Xs), time(maplist(m(Xs), Xs)).
% 5,350 inferences, 0.001 CPU in 0.001 seconds (99% CPU, 8248675 Lips)
Xs = [1, 2, 3, 4, 5, 6, 7, 8, 9|...] 

?- findall(X,between(1,100,X),Xs), time(concurrent_maplist(m(Xs), Xs)).
% 17,901 inferences, 0.024 CPU in 0.011 seconds (226% CPU, 733731 Lips)
Xs = [1, 2, 3, 4, 5, 6, 7, 8, 9|...].

?- findall(X,between(1,1000,X),Xs), time(concurrent_maplist(m(Xs), Xs)).
% 525,697 inferences, 0.253 CPU in 0.105 seconds (241% CPU, 2075994 Lips)
Xs = [1, 2, 3, 4, 5, 6, 7, 8, 9|...].

```

---

<div class="post-metadata">

**Author:** ![maximilianocristia](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/maximilianocristia/32/5377_2.png) [@maximilianocristia](https://swi-prolog.discourse.group/u/maximilianocristia)\
**Post date:** [April 7, 2023, 6:17am UTC](https://swi-prolog.discourse.group/t/overhead-of-concurrent-maplist/6440/3 "2023-04-07T06:17:56Z")

</div>

Thanks Peter! Good way of measuring the overhead. The overhead is in the order of magnitude I thought it would be… so our problem is in some other place.
