Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized C code by moving a variable outside of a loop. #287

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thurinj
Copy link
Member

@thurinj thurinj commented Nov 27, 2024

It seems that the repeated access to sources(isrc,ig) causes a slow-down that can be easily avoided by caching the source as:

double source_val = sources (isrc, ig)

in which gives the following:

// Sum cross-correlations of all components being considered
for (ig=0; ig<NG; ig++) {
  double source_val = sources (isrc, ig);
  for (it=0; it<NPAD; it++) {
      cc(it) += greens_data(ista,ic,ig,it) * source_val;
  }
}

since sources (isrc, ig) only changes with the outer part of the loop.

From local tests on my personal M1 Mac, this change yields a speedup of about ~x1.18.

Given that this modifies a key component of the code, I'd like @rmodrak to look at it before we proceed.

🛠 Note: No tentative merge date -- will be merged only upon review.

It seems that the repeated access to `sources(isrc,ig)` causes a slow-down that can be easily avoided by caching the source as:

```python3
double source_val = sources (isrc, ig)
```

From local test on an M1 mac, this yield a speedup of about ~1.18.

Changed variable name for consistency
@thurinj thurinj requested a review from rmodrak November 27, 2024 03:34
@rmodrak rmodrak self-assigned this Jan 13, 2025
Copy link
Member

@rmodrak rmodrak left a comment

Choose a reason for hiding this comment

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

Very helpful, looks good to me

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