Skip to main content

COMP 3400

To run nvhpc on Delta 

export PATH=/opt/nvidia/hpc_sdk/Linux_x86_64/25.11/compilers/bin:$PATH
export PATH=/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/mpi/bin:$PATH

Compile your code 

Thanks to Prof. Paul Preney for the test code  vecadd.cpp

// This program is very simple. Set size in main to be a large number if
// needed.
// vecadd.cpp

#include <cstddef>
#include <iostream>
#include <vector>
#include <numeric> // For iota
#include <algorithm> // For transform
#include <execution> // For parallel execution policies

void check(std::ostream& os, auto const& value, auto const& should_be_value)
{
  if (value == should_be_value)
    os << "OKAY";
  else
    os << "NOT_OKAY";
}

int main()
{
  using namespace std;

  size_t const size{ 1'000'000ULL};

  vector<int> a(size);
  vector<int> b(size);
  vector<int> result(size);

  iota(a.begin(), a.end(), 0); // a = {0, 1, 2, ...}
  iota(b.begin(), b.end(), size); // b = {size, size+1, ...}

  transform(execution::par_unseq,
    a.begin(), a.end(),
    b.begin(),
    result.begin(),
    [](int x, int y) { return x + y; }
  );

  // Verify a few elements (optional)
  cout << "result[0]: " << result[0] << ' '; check(cout,result[0],size); cout << '\n';
  cout << "result[1]: " << result[1] << ' '; check(cout,result[1],size+2); cout << '\n';
  cout << "result[size-1]: " << result[size-1] << ' '; check(cout,result[size-1],size-1+size*2-1); cout << '\n';
}

MakeFile

Makefile
CXXFLAGS=-O3

NVHPC_CXX=nvc++
NVHPC_CXXFLAGS=$(CXXFLAGS) --c++20 -stdpar=gpu
NVHPC_LDFLAGS=$(LDFLAGS)

GCC_CXX=g++
GCC_CXXFLAGS=$(CXXFLAGS) -std=c++20
GCC_LDFLAGS=$(LDFLAGS) -ltbb

all: vecadd-nvhpc.exe vecadd-gcc.exe

clean:
	rm *.exe

run: vecadd-gcc.exe vecadd-nvhpc.exe
	echo "Running vecadd-gcc.exe..."
	bash -c 'time ./vecadd-gcc.exe'
	echo -e "\n\n\n"
	echo "Running vecadd-nvhpc.exe..."
	bash -c 'time ./vecadd-nvhpc.exe'

%-nvhpc.exe : %.cpp
	$(NVHPC_CXX) $(NVHPC_CXXFLAGS) -o $@ $< $(NVHPC_LDFLAGS)

%-gcc.exe : %.cpp
	$(GCC_CXX) $(GCC_CXXFLAGS) -o $@ $< $(GCC_LDFLAGS)

image.png