Hello, I do not think multi-threading is possible with GiNaC, you may want to read one of the past discussion of this starting from here: https://www.ginac.de/pipermail/ginac-list/2010-August/001715.html Best wishes, Vladimir -- Vladimir V. Kisil http://v-v-kisil.scienceontheweb.net Book: Geometry of Mobius Maps https://doi.org/10.1142/p835 Soft: Geometry of cycles http://moebinv.sourceforge.net/ Jupyter notebooks: https://github.com/vvkisil?tab=repositories
On Fri, 07 Feb 2025 09:35:58 +0100, Bastian via GiNaC-list <ginac-list@ginac.de> said:
> Hello, I have a rather large number of expressions, > which I must normalize. To increase performance I wanted to > implement this on multiple threads. However, this always > segfaults and I am having trouble to find out where my error > is. Consider the following code: > ```c++ // H is a 9x9 matrix void norm_matrix(GiNaC::matrix& H) { > thread_pool tp = thread_pool(); auto n = 9; > std::vector<std::future<GiNaC::ex>> futures(n*n); for(int r = 0; r > < n; ++r) { for(int c = 0; c < n; ++c) { futures[r*n+c] = > tp.submit( [&h = H(r,c)] () -> GiNaC::ex { return h.normal(); }); > } } > for(int r = 0; r < n; ++r) { for(int c = 0; c < n; ++c) { > H(r,c) = futures[r*n+c].get(); } } } ``` At the second iterations > on the call of h.normal(), this crashes with a segfault, both with > a reference as well as with a copy. Has GiNaC been used in a > multithreaded environment previously and has this error occured? > Kind regards Spooky Ghost