Skip to content

Conversation

erykoff
Copy link
Contributor

@erykoff erykoff commented Feb 6, 2024

This is an env var banhammer to turn off implicit multithreading before any processes are spawned which may create threads on startup (I'm looking at you pytest plugins that import numpy on registration...)

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (80c3e6a) 87.50% compared to head (6d7afe0) 85.71%.

Files Patch % Lines
tests/test_simple.py 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #118      +/-   ##
==========================================
- Coverage   87.50%   85.71%   -1.79%     
==========================================
  Files           5        5              
  Lines          32       42      +10     
  Branches        2        3       +1     
==========================================
+ Hits           28       36       +8     
- Misses          2        3       +1     
- Partials        2        3       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of suggestions.

OPENBLAS_NUM_THREADS
NUMEXPR_MAX_THREADS
NUMEXPR_NUM_THREADS
""".split()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this way instead of making a list directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm following the code above ... when in Rome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the heck were they done that way?

@@ -215,6 +215,14 @@ def _initEnvironment():
CC_LOGGER_BIN
""".split()

implicitMultithreadingVars = """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a comment here about why you set these and how you found them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the list of variables to be more complete from lsst.utils even covering less common env vars.

Comment on lines +24 to +28
def testNoImplicitMultithreading(self):
"""Test that the environment has turned off implicit
multithreading.
"""
envVar = "OMP_NUM_THREADS"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything you could do in a test to try to spawn extra threads and confirm that it doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I don't know exactly that, but I did add a test to check the number of threads that numexpr thinks it has (following lsst.utils)

Comment on lines +32 to +35
try:
import numexpr
except ImportError:
numexpr = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try:
import numexpr
except ImportError:
numexpr = None
try:
import numexpr
self.assertEqual(numexpr.utils.get_num_threads(), 1)
except ImportError:
# It's not a problem if numexpr isn't available.
pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like putting extra code in the try block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, the ImportError can only be raised by one thing in it... I don't care that much, but I think it's simpler this way.

Although: when would numexpr not be available in the environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if sconsUtils is something that we ever may release separately and it doesn't really depend on numexpr, so I thought this was safer. And I didn't want to do the import up top because of all the reasons that this is necessary in the first place.

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please fix those split giant strings to lists?

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's better.

The new docstring is also helpful.

@erykoff erykoff merged commit 30fe544 into main Feb 7, 2024
@erykoff erykoff deleted the tickets/DM-42799 branch February 7, 2024 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants