Crash/lock when using several instances of SHTns in python

Issue #20 resolved
Former user created an issue

I have a setup where I need to use several separate spherical harmonic transforms to solve a problem, typically with different numbers of Lmax. However, I am experiencing problems doing this using the python bindings. Often (but not always!) the code locks (never completes) in the second call to set_grid. Running the code at the bottom produces

Lmax=35, Mmax*Mres=35, Mres=1, Nlm=666  [2 threads, orthonormalized]
Regular grid (mtr_dct=-1) : Nlat=180, Nphi=360
        syn   ana   vsy   van   gsp   gto   v3s   v3a 
   std: fly3   mem  omp3   mem  fly4  fly4  fly3   mem 
   ltr: fly3   mem  omp3   mem  fly4  fly4  fly3   mem 
     m: fly3  fly2  fly3  fly2  fly4  fly4  fly3  fly2 
*** [SHTns] Run-time error : bad SHT accuracy

while if I increase 35 to 50 or above it locks (not always though..) when calling set_grid in solver_b.initialize(). Is there something I have overlooked here? I'm using version 2.6.3-r520.

#!/usr/bin/env python

import shtns


class LSolver(object):


    def __init__(self, given_max_degree):

        self.max_degree  = given_max_degree

    def initialize(self):

        self.sht    = shtns.sht(self.max_degree, self.max_degree)

        grid_type   = shtns.sht_reg_fast | shtns.SHT_THETA_CONTIGUOUS

        self.sht.set_grid(180, 360, flags=grid_type)


if __name__ == "__main__":


    solver_a = LSolver(50)
    solver_b = LSolver(35)

    solver_a.initialize()
    solver_b.initialize()

Comments (3)

  1. Nathanaël Schaeffer repo owner

    Hi, sorry for the delay, I was in vacations.

    I can reproduce this bug, and I will need to investigate to see what's going on.

    As workarounds, I suggest:

    1) to avoid the lock, you can configure shtns using --disable-openmp --enable-python

    2) to avoid the "bad SHT accuracy", you should set up your multiple transform from lowest to highest resolution :

    solver_b = LSolver(35)
    solver_a = LSolver(50)
    
    solver_b.initialize()
    solver_a.initialize()
    

    Sorry for the inconvenience.

  2. Log in to comment