# A parallel and shared memory library based on Hack's implementation

**URL:** <https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428>\
**Category:** Community\
**Created:** [March 1, 2019, 6:58pm UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428 "2019-03-01T18:58:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvantonder](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rvantonder/32/223_2.png) [@rvantonder](https://discuss.ocaml.org/u/rvantonder)\
**Post date:** [March 1, 2019, 6:58pm UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428/1 "2019-03-01T18:58:22Z")

</div>

[Hack\_parallel](https://github.com/rvantonder/hack-parallel) is a standalone parallel and shared memory library based on the components used in FB tools [Hack](https://github.com/facebook/hhvm/tree/master/hphp/hack), [Flow](https://github.com/facebook/flow), and [Pyre](https://github.com/facebook/pyre-check). The internals of these components are little known outside of these projects, yet stand to benefit the OCaml community more generally, both for practical use and educational purposes. So I extracted the core parts and packaged it up; more information can be found in the project README.

I put together an [example project](https://github.com/rvantonder/hack-parallel-example) to illustrate the basic interface.

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [March 1, 2019, 7:52pm UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428/2 "2019-03-01T19:52:21Z")

</div>

Exciting stuff!

But how seriously should I take these warnings?

> <https://github.com/rvantonder/hack-parallel/blob/master/src/heap/hh_shared.c>

---

<div class="post-metadata">

**Author:** ![rvantonder](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rvantonder/32/223_2.png) [@rvantonder](https://discuss.ocaml.org/u/rvantonder)\
**Post date:** [March 1, 2019, 8:10pm UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428/3 "2019-03-01T20:10:03Z")

</div>

From [some more details](https://github.com/rvantonder/hack-parallel/#some-more-details):

You can ignore the scary THIS CODE ONLY WORKS WITH HACK. The implementation works generally (it’s used in Flow/Pyre and my own projects without problems). The warning is overcompensating so that people do not treat it like a “generic atomic hashtable for OCaml”. The data structure and constraints on memory operations are explained well [here](https://youtu.be/uXuYVUdFY48?list=WL&t=671). I may document the points in the video in future, but hope that helps for now.

---

<div class="post-metadata">

**Author:** ![olleharstedt](https://avatars.discourse-cdn.com/v4/letter/o/f1d935/32.png) [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Post date:** [November 1, 2020, 1:01am UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428/4 "2020-11-01T01:01:43Z")

</div>

Came here after googling around. This lib does not work on FreeBSD, for your information. 😉 When starting Flow (must be run as root because of access to /dev/null, for whatever reason), it fails with “Out of shared memroy”.

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [December 17, 2020, 1:00am UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428/5 "2020-12-17T01:00:14Z")

</div>

If you can show me that your library goes significantly faster than this one:

> **[UnixJunkie/parany](https://github.com/UnixJunkie/parany)**
>
> Parallelize \_anything\_ //. Contribute to UnixJunkie/parany development by creating an account on GitHub.

Then, and only then, I will have a serious look at it. 😉

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [December 17, 2020, 1:00am UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428/6 "2020-12-17T01:00:59Z")

</div>

Open an issue in their bug tracker man…

---

<div class="post-metadata">

**Author:** ![aryx](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/aryx/32/2356_2.png) [@aryx](https://discuss.ocaml.org/u/aryx)\
**Post date:** [December 18, 2020, 1:05pm UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428/7 "2020-12-18T13:05:38Z")

</div>

What is the difference between parany and parmap by dicosmo?  
If you rely on fork to process things in parallel, then here you have your difference: the hacks’s parallel library shines if you need shared memory. It’s like a poor’s man multicore while waiting for the official multicore in OCaml 5.0.

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [December 21, 2020, 1:28am UTC](https://discuss.ocaml.org/t/a-parallel-and-shared-memory-library-based-on-hacks-implementation/3428/8 "2020-12-21T01:28:48Z")

</div>

Parany can process in parallel an infinite stream.  
Parmap cannot.
