OpenACC pragmas for C programs

I am using OpenACC to check if the pragmas that I inserted into multiple C programs was done correctly.
I have tagged the for loops in multiple C files that have h and o file dependencies.

So, after I get all of the pragmas correct, and compile my program normally, what should I do so that the pragmas behave as expected? It appears that OpenACC won’t run a pre-compiled C program.

Thanks.

Some things are not clear.

If you have an openACC code that compiles correctly, and you have decorated for loops either with the

#pragma acc kernels

#pragma acc parallel

directive, then there shouldn’t be anything else needed to get those accelerated regions to run on the GPU. If you are using the PGI compiler toolchain for this, the -Minfo=accel compiler switch is a useful thing to use and learn to understand its output.

When you say “It appears that OpenACC won’t run a pre-compiled C program.”, I’m not sure what you mean.

Yes, its correct that a pre-compiled program (say, one that does not use OpenACC) will not automatically use the GPU. You have to compile code specifically to use the GPU. It is also correct that if you are calling a library function that is calling into a pre-compiled host code library, such calls can’t be made from accelerator regions (i.e. those regions decorated as I described above).

It might be useful just to go through an introductory course on OpenACC.

Thank you Robert.

Just to clarify further:

I am working on C files from a well known bioinformatics program. It has a mix of o and h files as well.
What I’ve done previously is decorate the for loops with pragmas and then follow the bioinformatics programs normal compile instructions.

How do I compile the bioinformatics program to use GPUs? Do you have links to tutorials, I’m having trouble finding this on the internet.

That won’t work, i.e. it will not use the GPU. The idea behind a pragma in C/C++ is that:

  1. For a toolchain that is aware of the purpose of the pragma, it has the desired effect
  2. For a toolchain that is not aware of the pragma, it is treated as whitespace (it has no effect).

So decorating that way, but compiling “normally” will have no effect (assuming the “normal compile instructions” don’t call out a OpenACC-aware toolchain.)

Decoration with pragmas is the first step. The second and mandatory step is to use a OpenACC-aware compiler.

If you want to use the PGI compiler there are quite a few resources available. I googled “PGI OpenACC tutorial” and got quite a few useful hits in the first page. These seem like a good place to start:

https://www.youtube.com/watch?v=PxmvTsrCTZg
https://www.youtube.com/watch?v=0e5TiwZd_wE
https://devblogs.nvidia.com/openacc-example-part-1/

For longer treatments, openacc.org publishes lots of useful material:

https://www.openacc.org/resources

NVIDIA also offers openacc training in an on-demand fashion via Deep Learning Institute. point your browser here:
https://courses.nvidia.com/courses
then type “openacc” into the search box.