Bug in map_rect with threading in Stan 2.18.0

Here is a Python script to run (improved over my old version by @ahartikainen) with the size of the collection you are running map_rect over (called shards here) and the number of threads you configured (threads):


def showsbug(shards, threads):
    if threads < 2:
        return False
    return shards % min(shards, threads) == threads - 1

This returns True if your workload should display the threading bug and you should re-run (likely re-running with a different number of threads or size of collection should solve it, but test with this function). I am pretty embarrassed that I couldn’t quickly find a closed-form solution to this question, but there may not be one due to all of the special logic in here, and this seems good enough.

To illustrate with the example that @ermeel was running here, you would run this function with size=3 and threads=2: showsbug(3, 2) (which shows True).

3 Likes