### Compiling and Running the C Example Source: https://docs.nvidia.com/hpc-sdk/archive/23.9/compilers/hpc-compilers-user-guide/index Provides the compiler command to build the C example executable and demonstrates how to run it with specific environment variables to observe the PCAST comparison output. ```bash > nvc -fast -o a.out example.c > PCAST_COMPARE=summary,rel=1 ./out.o datafile pcast_compare.dat created with 5 blocks, 5000 elements, 20000 bytes > PCAST_COMPARE=summary,rel=1 ./out.o datafile pcast_compare.dat compared with 5 blocks, 5000 elements, 20000 bytes no errors found relative tolerance = 0.100000, rel=1 ``` -------------------------------- ### NVIDIA OpenACC Environment Variable Configuration Examples Source: https://docs.nvidia.com/hpc-sdk/archive/25.5/compilers/openacc-gs/index Examples demonstrating how to set NVIDIA OpenACC environment variables to control runtime behavior. These variables must be in uppercase and their values are case-insensitive. Changing values after program start can lead to implementation-defined behavior. ```shell # Set NVCOMPILER_ACC_DEVICE_NUM to use device 0 export NVCOMPILER_ACC_DEVICE_NUM=0 # Set NVCOMPILER_ACC_DEVICE_TYPE to NVIDIA devices export NVCOMPILER_ACC_DEVICE_TYPE=NVIDIA # Enable profiling library export NVCOMPILER_ACC_PROFLIB=1 # Disable asynchronous launches and data movement export NVCOMPILER_ACC_SYNCHRONOUS=1 # Enable lightweight profiler for timing export NVCOMPILER_ACC_TIME=1 # Enable debug messages for kernel launches and data transfers export NVCOMPILER_ACC_NOTIFY=3 ``` -------------------------------- ### -help Option Output Example Source: https://docs.nvidia.com/hpc-sdk/archive/23.3/compilers/hpc-compilers-user-guide/index Presents example output from the -help option when querying the -fast flag, showing its constituent optimizations. It also demonstrates the syntax for retrieving grouped help information. ```shell -fast Common optimizations; includes -O2 -Munroll=c:1 -Mnoframe -Mlre ``` ```shell -help[=groups|asm|debug|language|linker|opt|other|overall|phase|prepro| suffix|switch|target|variable] ``` -------------------------------- ### OpenACC Atomic Operation Example Source: https://docs.nvidia.com/hpc-sdk/archive/25.11/compilers/openacc-gs/index Shows the implementation of OpenACC atomic operations for safe concurrent updates to shared memory locations within accelerator regions. This example uses a reduction pattern. ```c double *a, *b, *c; . . . #pragma acc loop vector for (int k = 0; k < n; ++k) { #pragma acc atomic c[i*n+j] += a[i*n+k]*b[k*n+j]; } ``` -------------------------------- ### Show Compiler Switches Help Source: https://docs.nvidia.com/hpc-sdk/archive/23.5/compilers/hpc-compilers-user-guide/index This example displays the help information for compiler switches, providing details on various compiler options and their functionalities. ```shell -help=groups|asm|debug|language|linker|opt|other|overall| phase|prepro|suffix|switch|target|variable ``` -------------------------------- ### Fortran Vector Addition using OpenACC Source: https://docs.nvidia.com/hpc-sdk/archive/25.5/compilers/openacc-gs/index This Fortran example illustrates vector addition accelerated on the GPU using OpenACC. It is presented as the simplest Fortran example for OpenACC, focusing on the core GPU computation. ```fortran program vecadd integer, parameter :: n = 100000 real a(n), b(n), r(n), e(n) integer i, errs do i = 1, n a(i) = real(i) b(i) = real(1000*i) end do ! compute on the GPU !$acc data copyin(a,b) copyout(r) !$acc kernels do i = 1, n r(i) = a(i) + b(i) end do !$acc end kernels !$acc end data ! compute on the host to compare do i = 1, n e(i) = a(i) + b(i) end do ! compare results errs = 0 do i = 1, n if (r(i) .ne. e(i)) then errs = errs + 1 end if end do print *, errs, " errors found" stop end program vecadd ``` -------------------------------- ### Compiling and Running the C Example Source: https://docs.nvidia.com/hpc-sdk/pgi-compilers/20.1/openpower/pgi-user-guide/index Provides the command-line instructions to compile the C example using pgcc and how to run the compiled executable with specific PGI_COMPARE environment variables to observe the comparison output. It shows the output for both the initial run (creating the data file) and subsequent runs. ```bash > pgcc -fast -o a.out example.c > PGI_COMPARE=summary,rel=1 ./out.o datafile pgi_compare.dat created with 5 blocks, 5000 elements, 20000 bytes > PGI_COMPARE=summary,rel=1 ./out.o datafile pgi_compare.dat compared with 5 blocks, 5000 elements, 20000 bytes no errors found relative tolerance = 0.100000, rel=1 ``` -------------------------------- ### Compile with OpenACC directives Source: https://docs.nvidia.com/hpc-sdk/archive/25.7/compilers/openacc-gs/index Shows how to enable OpenACC directives using the `-acc` compiler flag. This example illustrates basic compilation for GPU offloading. ```bash nvc -acc my_program.c -o my_program ``` -------------------------------- ### Compiling and Running OpenACC Example Source: https://docs.nvidia.com/hpc-sdk/archive/25.11/compilers/openacc-gs/index This example shows the command-line invocation to compile an OpenACC application targeting the cc70 (Volta) GPU architecture and the subsequent execution. It demonstrates a scenario where PTX JIT compilation might be necessary and potentially problematic due to CUDA driver version mismatches. ```bash $ nvc -acc -gpu=cc70 app.c $ ./a.out ``` -------------------------------- ### Verify C Compiler Installation (C) Source: https://docs.nvidia.com/hpc-sdk/archive/24.3/hpc-sdk-install-guide/index This snippet demonstrates how to create and compile a simple 'hello, world!' C program to verify the installation and functionality of the gcc compiler. It includes creating the source file, compiling it, and using the 'file' command to inspect the resulting executable. ```c #include int main() { printf("hello, world!\n"); return 0; } ``` ```bash $ gcc -o hello_c hello.c ``` ```bash $ file ./hello_c ``` ```text hello_64_c: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped ``` -------------------------------- ### Querying Compiler Options with -help Source: https://docs.nvidia.com/hpc-sdk/archive/20.7/compilers/hpc-compilers-user-guide/index Shows how to use the -help option to retrieve information about compiler commands. The first example queries information about the -fast option, displaying its included optimizations. The second example queries the -help option itself, showing its various subgroup parameters. ```shell $ nvfortran -help -fast ``` ```shell $ nvfortran -help -help ``` -------------------------------- ### OpenACC PRINT Statement Example Source: https://docs.nvidia.com/hpc-sdk/archive/25.11/compilers/openacc-gs/index Demonstrates the use of `PRINT` statements within an OpenACC compute region for outputting various data types. Supports integer, character, logical, real, and complex types, with buffering for efficient line printing. ```fortran program t integer(4) a(10000) a = [ (1+i,i=1,10000) ] !$acc kernels do i = 1, 10000 if (a(i)/3000*3000.eq.a(i)) print *," located ",i,a(i),i.gt.5000,a(i)/5.0 end do !$acc end kernels end ``` -------------------------------- ### Compiling and Running MPI Hello World Example with Open MPI Source: https://docs.nvidia.com/hpc-sdk/archive/21.2/compilers/hpc-compilers-user-guide/index Demonstrates how to compile and run a simple MPI 'Hello, world!' program using Open MPI on Linux. It involves copying an example, setting the PATH for Open MPI binaries, and then compiling and executing the program. The execution can be done on a single process or multiple processes using 'mpiexec'. ```bash $ cd my_example_dir $ cp -r /opt/nvidia/hpc_sdk/Linux_x86_64/2021/examples/MPI/samples/mpihello . $ cd mpihello $ export PATH=/opt/nvidia/hpc_sdk/Linux_x86_64/21.2/mpi/openmpi/bin:$PATH $ mpifort mpihello.f -o mpihello $ mpiexec mpihello Hello world! I'm node 0 $ mpiexec -np 4 mpihello Hello world! I'm node 0 Hello world! I'm node 2 Hello world! I'm node 1 Hello world! I'm node 3 ``` -------------------------------- ### Verify Installed Compiler Release (Bash) Source: https://docs.nvidia.com/hpc-sdk/pgi-compilers/20.1/x86/pgi-install-guide/index These commands verify the release number of installed PGI compilers. They can be executed before or after license installation to confirm the correct version and environment setup. ```bash pgf77 -V ``` ```bash pgfortran -V ``` ```bash pgcc -V ``` -------------------------------- ### Target Specific GPU Architectures Source: https://docs.nvidia.com/hpc-sdk/archive/25.5/compilers/openacc-gs/index Use the '-gpu' flag with compiler compute capability codes (ccXY) to target specific NVIDIA GPU architectures. This allows for optimized code generation for different GPU generations. For example, '-gpu=cc70' targets Volta GPUs. ```shell // Target a specific GPU architecture (e.g., Volta) "nvfortran" -acc -gpu=cc70 my_program.f90 -o my_program "nvc++" -acc -gpu=cc70 my_program.cpp -o my_program ``` ```shell // Target multiple GPU architectures "nvfortran" -acc -gpu=cc70,cc86 my_program.f90 -o my_program "nvc++" -acc -gpu=cc70,cc86 my_program.cpp -o my_program ``` -------------------------------- ### Compiling and Running an Open MPI 'Hello World' Example Source: https://docs.nvidia.com/hpc-sdk/pgi-compilers/18.7/x86/pgi-user-guide/index This example demonstrates how to compile and run a simple MPI 'Hello World' program using Open MPI with the PGI compilers on Linux/macOS. It involves setting up the environment, compiling, and executing the MPI application. ```bash $ cd my_example_dir $ cp -r $PGI/linux86-64/18.7/EXAMPLES/MPI/mpihello . $ cd mpihello $ export PATH=$PGI/linux86-64/2018/mpi/openmpi/bin:$PATH $ mpif90 mpihello.f -o mpihello ``` ```bash $ mpiexec mpihello Hello world! I'm node 0 ``` ```bash $ mpiexec -np 4 mpihello Hello world! I'm node 0 Hello world! I'm node 2 Hello world! I'm node 1 Hello world! I'm node 3 ``` -------------------------------- ### Extract and Install PGI Compilers Source: https://docs.nvidia.com/hpc-sdk/pgi-compilers/18.3/openpower/pgi-release-notes/index Demonstrates the initial steps for a network installation of PGI compilers. It involves extracting a tarball and running an installation script, followed by selecting the 'Network install' option during the interactive setup. ```bash tar zxpf pgilinux-2018-183-ppc64le.tar.gz ./install ... At the "Please choose install option:" prompt, choose "Network install". ``` -------------------------------- ### Start License Manager Daemon Source: https://docs.nvidia.com/hpc-sdk/pgi-compilers/19.3/x86/pgi-install-guide/index Command to start the license server and pgroupd license daemon. Assumes installation in a non-default directory and requires navigating to the bin directory. This command is not needed for Community Edition or starter licenses. ```shell % cd $PGI/linux86-64/19.3/bin/ % ./lmgrd.rc start ``` -------------------------------- ### Nested OpenACC Compute Constructs with Class Member Functions Source: https://docs.nvidia.com/hpc-sdk/archive/25.11/compilers/openacc-gs/index OpenACC compute constructs can contain other compute constructs. This example demonstrates a parallel loop within a class member function, where 'this' and the passed class object 'y' are explicitly placed in the 'present' clause for correct device data handling. ```c++ template class dupvector{ ... void inc2( dupvector &y ){ int n = size; #pragma acc parallel loop gang vector present(this,y) for( int i = 0; i < n; ++i ) data[i] += y[i]; } } ... v.inc2( x ); ``` -------------------------------- ### Example Output of -help -help Source: https://docs.nvidia.com/hpc-sdk/pgi-compilers/19.5/openpower/pgi-user-guide/index Displays the output for the command '$ pgfortran -help -help', which details the usage of the '-help' option itself, including how to specify subgroups of options for more targeted information. ```text -help[=groups|asm|debug|language|linker|opt|other|overall|phase|prepro| suffix|switch|target|variable] ``` -------------------------------- ### Build and Run Example - step1 Source: https://docs.nvidia.com/hpc-sdk/archive/20.11/compilers/openacc-mpi-tutorial/index Instructions for building and running the `step1` example code on a system with NVIDIA HPC SDK compilers and MPI wrappers. This involves navigating to the `step1` directory, compiling the code, executing it, and verifying the results. ```shell cd step1 make build make run make verify ``` -------------------------------- ### Compile with OpenACC Directives using NVIDIA HPC Compilers Source: https://docs.nvidia.com/hpc-sdk/archive/22.7/compilers/openacc-gs/index This example demonstrates how to enable OpenACC directives during compilation using the NVIDIA HPC Compilers. The `-acc` flag activates OpenACC, and additional flags like `-gpu=cc70` can specify the target GPU compute capability. ```c++ nvfortran -acc -gpu=cc70 my_program.f90 nvc++ -acc -gpu=cc70 my_program.cpp ncc -acc -gpu=cc70 my_program.c ``` -------------------------------- ### acc_memcpy_to_device Routine Source: https://docs.nvidia.com/hpc-sdk/archive/25.11/compilers/openacc-gs/index The acc_memcpy_to_device routine copies data from local memory (host) to device memory. ```APIDOC ## acc_memcpy_to_device ### Description Copies data from host memory to device memory. ### Method SUBROUTINE ### Parameters #### Call Format 1: - **dev** (CUDA Fortran device variable, array, or starting element) - Destination device memory. - **src** (host variable, array, or starting element) - Source host memory. - **bytes** (integer) - Length of the copy in bytes. #### Call Format 2: - **dev** (CUDA Fortran device array or contiguous array section) - Destination device memory. - **src** (host array or array section) - Source host memory, must conform to dev. #### Call Format 3: - **devptr** (type(c_devptr)) - Destination device pointer. - **src** (host variable, array, or starting element) - Source host memory. - **bytes** (integer) - Length of the copy in bytes. #### Call Format 4: - **devptr** (type(c_devptr)) - Destination device pointer. - **ptr** (type(c_ptr)) - Source host pointer. - **bytes** (integer) - Length of the copy in bytes. ### Request Example ```fortran ! Example for Call Format 1 subroutine acc_memcpy_to_device( device_var, host_var, num_bytes ) ! Example for Call Format 2 subroutine acc_memcpy_to_device( device_array, host_array ) ! Example for Call Format 3 subroutine acc_memcpy_to_device( device_ptr, host_var, num_bytes ) ! Example for Call Format 4 subroutine acc_memcpy_to_device( device_ptr, host_ptr, num_bytes ) ``` ### Response This routine does not return a value, but performs the memory copy operation. ```