# \#pragma omp parallel: igraph\_error.c:186: IGRAPH\_FINALLY\_REAL: Assertion \`no \< 100' failed

**URL:** <https://igraph.discourse.group/t/pragma-omp-parallel-igraph-error-c-igraph-finally-real-assertion-no-100-failed/469>\
**Category:** Usage\
**Tags:** C\
**Created:** [7 October 2020 12:23 UTC](https://igraph.discourse.group/t/pragma-omp-parallel-igraph-error-c-igraph-finally-real-assertion-no-100-failed/469 "2020-10-07T12:23:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecopeng](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ecopeng/32/441_2.png) [@ecopeng](https://igraph.discourse.group/u/ecopeng)\
**Post date:** [7 October 2020 12:23 UTC](https://igraph.discourse.group/t/pragma-omp-parallel-igraph-error-c-igraph-finally-real-assertion-no-100-failed/469/1 "2020-10-07T12:23:11Z")

</div>

Dear igraph users,

I’m running my c++ code under multiple threads on Ubuntu with OpenMP and functions from the igraph c library. However, sometimes I get the error ‘igraph\_error.c:186: IGRAPH\_FINALLY\_REAL: Assertion `no \< 100’ failed.’, and when I run it without parallelism, there’s no error.

Could any of you give some hints about what’s going wrong?

Thanks in advance.  
Peng

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [8 October 2020 13:36 UTC](https://igraph.discourse.group/t/pragma-omp-parallel-igraph-error-c-igraph-finally-real-assertion-no-100-failed/469/2 "2020-10-08T13:36:28Z")

</div>

In order to use igraph in a multi-threaded setting, you must pass the option `--enable-tls` (enable thread-local storage) to `./configure` when compiling igraph. This _should_ resolve the problem you are seeing, but this option is not very well tested. Personally, I have never used igraph from multiple threads.

Note that this option does not make it safe to manipulate `igraph_t` objects from multiple threads. If you are running a graph algorithm which only reads, but never modifies the graph, then it should be okay. Trying to modify the graph from multiple threads will mess things up though.

Let us know how it went with `--enable-tls`. Feedback is always welcome.

---

<div class="post-metadata">

**Author:** ![ecopeng](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ecopeng/32/441_2.png) [@ecopeng](https://igraph.discourse.group/u/ecopeng)\
**Post date:** [18 October 2020 10:28 UTC](https://igraph.discourse.group/t/pragma-omp-parallel-igraph-error-c-igraph-finally-real-assertion-no-100-failed/469/3 "2020-10-18T10:28:04Z")

</div>

Thanks for the response.

I think in my case it was very likely because of data racing when writing from different threads to the shared object. I did not re-compile igraph with the --enable-tls flag, and instead, I declared that each thread should copy (and thus initialized with) the shared object first before computing, by adding the firstprivate clause in the OpenMP section, and it worked (i.e. instead of writing to the shared object, I copy it in each thread and write to the copies as temporal objects independently). Sorry my code is too long to demonstrate how it worked here, and it seems the problem had nothing to do with the igraph but my fault.

P

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [18 October 2020 10:59 UTC](https://igraph.discourse.group/t/pragma-omp-parallel-igraph-error-c-igraph-finally-real-assertion-no-100-failed/469/4 "2020-10-18T10:59:10Z")

</div>

igraph uses global data structures _internally_, for error handling. If these are shared between threads, something is pretty much guaranteed to fail eventually. It is not sufficient to copy an `igraph_t` that you are working with.

**EDIT: To be clear, what you are doing is bound to fail, whether your program has already crashed or not. Any readers of this beware, do _not_ do this!**

---

<div class="post-metadata">

**Author:** ![ecopeng](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ecopeng/32/441_2.png) [@ecopeng](https://igraph.discourse.group/u/ecopeng)\
**Post date:** [18 October 2020 13:54 UTC](https://igraph.discourse.group/t/pragma-omp-parallel-igraph-error-c-igraph-finally-real-assertion-no-100-failed/469/5 "2020-10-18T13:54:54Z")

</div>

Thanks and good to know that 🙂  
I avoided using igraph\_t and used matrices (igraph\_matrix\_t) instead in such case, and things seem went smoothly.

P

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [18 February 2021 14:43 UTC](https://igraph.discourse.group/t/pragma-omp-parallel-igraph-error-c-igraph-finally-real-assertion-no-100-failed/469/6 "2021-02-18T14:43:25Z")

</div>

> [@ecopeng](#):
>
> I avoided using igraph\_t and used matrices (igraph\_matrix\_t) instead in such case, and things seem went smoothly.

**Another big warning to any readers:**

It makes no difference if you use `igraph_t` or not. igraph functions are not safe to use from multiple threads unless igraph was compiled with the appropriate settings to be thread safe. Even then, special care is needed. Documentation is here:

[https://igraph.org/c/doc/igraph-Advanced.html#using-igraph-in-multi-threaded-programs](https://igraph.org/c/doc/igraph-Advanced.html#using-igraph-in-multi-threaded-programs)
