sympy/csympy — pull request #218 by certik (2014-06-26 23:04:52+00:00)
Title: [WIP] Use std::atomic to achieve thread safety

Things get around 30% slower, but now csympy should be thread safe (/cc @bluescarni). So this doesn't make sense on a single core, but if you get 2x speedup on two cores, then it makes sense to use it.

TODO:

* [ ] Introduce an extra cmake flag `WITH_THREAD_SAFE` which would be off by default, but can be turned on. Only use `std::atomic` if this flag is on. Add Travis tests.

Master:
```
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand1
Expanding: (y + x + z + w)^60
105ms
number of terms: 39711
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand1
Expanding: (y + x + z + w)^60
101ms
number of terms: 39711
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand1
Expanding: (y + x + z + w)^60
104ms
number of terms: 39711
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand1
Expanding: (y + x + z + w)^60
105ms
number of terms: 39711
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand2
Expanding: ((y + x + z + w)^15 + w)*(y + x + z + w)^15
1047ms
number of terms: 6272
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand2
Expanding: ((y + x + z + w)^15 + w)*(y + x + z + w)^15
1052ms
number of terms: 6272
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand2
Expanding: ((y + x + z + w)^15 + w)*(y + x + z + w)^15
1056ms
number of terms: 6272
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand2
Expanding: ((y + x + z + w)^15 + w)*(y + x + z + w)^15
1054ms
number of terms: 6272
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand3
Expanding: (z^x + x^y + y^x)^100
33ms
number of terms: 5151
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand3
Expanding: (z^x + x^y + y^x)^100
32ms
number of terms: 5151
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand3
Expanding: (z^x + x^y + y^x)^100
36ms
number of terms: 5151
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand3
Expanding: (z^x + x^y + y^x)^100
32ms
number of terms: 5151
```
this PR:
```
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand1
Expanding: (y + x + z + w)^60
120ms
number of terms: 39711
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand1
Expanding: (y + x + z + w)^60
117ms
number of terms: 39711
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand1
Expanding: (y + x + z + w)^60
121ms
number of terms: 39711
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand1
Expanding: (y + x + z + w)^60
118ms
number of terms: 39711
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand2
Expanding: ((y + x + z + w)^15 + w)*(y + x + z + w)^15
1385ms
number of terms: 6272
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand2
Expanding: ((y + x + z + w)^15 + w)*(y + x + z + w)^15
1399ms
number of terms: 6272
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand2
Expanding: ((y + x + z + w)^15 + w)*(y + x + z + w)^15
1377ms
number of terms: 6272
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand2
Expanding: ((y + x + z + w)^15 + w)*(y + x + z + w)^15
1378ms
number of terms: 6272
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand3
Expanding: (z^x + x^y + y^x)^100
44ms
number of terms: 5151
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand3
Expanding: (z^x + x^y + y^x)^100
42ms
number of terms: 5151
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand3
Expanding: (z^x + x^y + y^x)^100
41ms
number of terms: 5151
ondrej@kittiwake:~/repos/csympy/benchmarks(master)$ ./expand3
Expanding: (z^x + x^y + y^x)^100
45ms
number of terms: 5151
```