Skip to content

World MultiThreadTemplate

Clifford Bohm edited this page Jul 28, 2017 · 2 revisions

THIS WORLD DOES NOT SHIP WITH DEFAULT MABE, it exists simply to demonstrate how multithreading can be implemented. If you are interested in getting the code for this world, please contact us.

MultiThreadTemplate World

There are multiple ways how you could speed up your runs. One simple option is to use multithreading (by using the commonly available pthread.h library). However, now that you are multithreading things, you need to be thread save in what you are doing. To ensure this, we recommend changing this template world in which you can evaluate multiple organisms in parallel. In essence, you create a function evaluateSoloMultiThread which will then be executed in such a way that you can now evaluate multiple organisms at the same time. However there are a couple of caveats that you MUST take into account:

  • you can not have agents interact with each other since you are not guaranteed to have both agents on the same thread, hence the evaluateSolo idea.
  • you should use a population size that can be divided equally over all threads you want to use. In theory, we could call one thread that computes the dangling organisms, but we think that this is silly. So if you use 4 threads your population size must be dividable by 4 without any remainder.
  • dataMap and all your other pointers are threadsave, so if you mess with those elsewhere you might interfear with this feature.
  • pthread forces us to use a static function and thus you currently can't use multiple worlds in parallel, that would mess with the multithreading in a very bad way.
Clone this wiki locally