X
3011

Example: how to call IDL codes from Multiprocessing Python Package

 

Below is an example about how to call IDL commands from the multiprocessing Python library. The multiprocessing Python package can be used to parallelize processes in Python. IDL can take benefit of this package using the Python to IDL bridge

 

1. Create a python module to import the IDL package and call the IDL commands.

For example, create a defs.py file with f function including

  • The import of the IDL package
  • The calls to IDL commands

def f(i):

        from idlpy import IDL

        i = IDL.sqrt(i); IDL.wait(10)

        return i+1

 

​2. Create a python code to call the python module created at step 1, and run it using the multiprocessing python package

For example, create a run.py file including

  • The import of the python multiprocessing package
  • The import of the defs.py python module
  • The call to defs.f function using the multiprocessing package

import time

start = time.time()

from multiprocessing import Pool

import defs       

if __name__ == '__main__':

                with Pool(3) as p:

                                print(p.map(defs.f, [9,16,25]))

end = time.time()

print(end - start)

 

3. Run the main python code in Python, after configuring the Python to IDL bridge.

https://www.l3harrisgeospatial.com/docs/python.html

For example run at a prompt:

python run.py

This example should return:

IDL 8.8 (linux x86_64 m64).

(c) 2021, Harris Geospatial Solutions, Inc.

IDL 8.8 (linux x86_64 m64).

(c) 2021, Harris Geospatial Solutions, Inc.

IDL 8.8 (linux x86_64 m64).

(c) 2021, Harris Geospatial Solutions, Inc.

Licensed for use by: xxxxxx

License: 1234

Licensed for use by: xxxxx

License: 1234

Licensed for use by: xxxxx

License: 1234-server-linux

[4.0, 5.0, 6.0]

10.561610221862793

 

 

 

______________________________

created by BC on 8/17/2021 - reviewed by BC(US)