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

Adds -fopenmp flag to omp kernels + adds c++20 omp kernel #100

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

mcbarton
Copy link
Collaborator

@mcbarton mcbarton commented May 16, 2024

This PR adds the openmp kernels (with the addition of a c++20 openmp kernel), setting the flag -fopenmp for those kernels which need it. @vgvassilev This PR is ready for review.

@mcbarton mcbarton force-pushed the Add-fopenmp-flag-for-omp-kernels branch from f1f309b to d6a132b Compare May 16, 2024 09:01
@codecov-commenter
Copy link

codecov-commenter commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.66%. Comparing base (f20af56) to head (03d9c97).
Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #100      +/-   ##
==========================================
+ Coverage   53.66%   62.66%   +9.00%     
==========================================
  Files          15       15              
  Lines         600      600              
  Branches       59       59              
==========================================
+ Hits          322      376      +54     
+ Misses        278      224      -54     

see 5 files with indirect coverage changes

see 5 files with indirect coverage changes

@mcbarton mcbarton force-pushed the Add-fopenmp-flag-for-omp-kernels branch from 5a9061e to 658ebae Compare May 16, 2024 09:18
@mcbarton
Copy link
Collaborator Author

@anutosh491 Are you able to review this PR, and merge if your happy with it?

@anutosh491
Copy link
Collaborator

Sure I can have a look in a while.

@vgvassilev
Copy link
Contributor

Can we add a test for making sure that openmp works? IIRC, @alexander-penev and I had something as a demo in xeus-clang-repl somewhere...

@mcbarton
Copy link
Collaborator Author

Can we add a test for making sure that openmp works? IIRC, @alexander-penev and I had something as a demo in xeus-clang-repl somewhere...

Yes, i'll add a test tomorrow and cc you when it passes.

@vgvassilev vgvassilev requested review from JohanMabille and alexander-penev and removed request for JohanMabille May 20, 2024 08:33
assert reply is not None
self.assertEqual(reply["msg_type"], "is_complete_reply")
self.assertEqual(reply["content"]["status"], "complete")
self.assertEqual(reply['content']['matches'], '2')
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that enough to make sure that we spawn multiple threads?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

omp_set_thread_num(4) in the code will make sure we use use 4 threads for all parallel regions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My issue at the moment is getting the test to pass. Trying to see whether the output comes out as 2 as expected, since only that thread should output.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can’t we call get_num_threads and make sure the result is different than 1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm open to suggestions on what code you'd like me to try. At the moment I can't get the code I am trying to run to work, to even be able to test it. It just timeouts whenever I try and run my code, with no useful output as to what caused the timeout.

Copy link
Contributor

Choose a reason for hiding this comment

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

@alexander-penev, you are the one that made this work last time for xeus-clang-repl, any clues?

@mcbarton, can we maybe add a test in CppInterOp to make sure it works in openmp mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@vgvassilev yes i'll look into an openmp test for CppInterOp

code_omp='#include <iostream>\n#include "omp.h"\n#include "clang/Interpreter/CppInterOp.h"\nCpp::LoadLibrary("libomp");omp_set_thread_num(4);#pragma omp parallel\n{\nif(omp_get_thread_num()==2) std::cout<<omp_get_thread_num()<<std::endl;}'
def test_xcpp_omp(self):
self.flush_channels()
reply, output_msgs = self.execute_helper(code=self.code_omp,timeout=100)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to dump reply and output_msgs as string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I now have it running without timeout. It says it cannot find the omp header.

Copy link
Collaborator Author

@mcbarton mcbarton May 20, 2024

Choose a reason for hiding this comment

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

@vgvassilev @alexander-penev
The error I got after I managed to avoid the timeout issue is
input_line_11:2:10: fatal error: 'omp' file not found
E - 2 | #include
E - | ^~~~~
E - Failed to parse via ::process:Parsing failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to have failed to pass the relevant -I or we did not install openmp?

Copy link
Collaborator Author

@mcbarton mcbarton May 21, 2024

Choose a reason for hiding this comment

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

I've managed to make progress in that it now finds omp.h and runs things such as Cpp::LoadLibrary("libomp"),omp_get_max_threads() and omp_set_thread_num(). Now I just need to work out why it doesn't like my parallel section.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue looks like its with the line #pragma omp parallel, but unsure what exactly it doesn't seem to like.

@mcbarton mcbarton marked this pull request as draft May 21, 2024 12:45
@mcbarton mcbarton force-pushed the Add-fopenmp-flag-for-omp-kernels branch from 36978f0 to 328b5cb Compare May 21, 2024 17:29
@mcbarton mcbarton force-pushed the Add-fopenmp-flag-for-omp-kernels branch from d1ba6ad to 25a8085 Compare May 22, 2024 14:25
@mcbarton
Copy link
Collaborator Author

@alexander-penev how did you get the openmp library in xeus-clang-repl? That appears to be what is holding back this PR. I've tried multiple different ways without sucess, but I cannot get Cpp::LoadLibrary to load the libomp library, to be able to test the openmp kernel.

@vgvassilev
Copy link
Contributor

@alexander-penev how did you get the openmp library in xeus-clang-repl? That appears to be what is holding back this PR. I've tried multiple different ways without sucess, but I cannot get Cpp::LoadLibrary to load the libomp library, to be able to test the openmp kernel.

I remember it was a huge mess before we sorted it out. I have no memory what we did though. However, it should be in the Dockerfile of xeus-clang-repl...

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.

5 participants