Hi,
Is it possible for nvc++ to use function objects defined in a different translation unit to the one calling a C++ standard library algorithm? As a small example, if the contents of 3 files, main.cpp, squared.cpp and squared.hpp are:
main.cpp:
#include "squared.hpp"
#include <vector>
#include <iostream>
#include <algorithm>
#include <execution>
int main(int argc, char *argv[])
{
std::vector<int> v(1<<20,7);
const auto pol = std::execution::par_unseq;
std::for_each(pol, v.begin(), v.end(), squared{});
std::cout << v[0] << '\n';
return 0;
}
squared.cpp:
#include "squared.hpp"
void squared::operator()(int& x) { x = x * x; }
squared.hpp:
#ifndef __SQUARED_HPP__
#define __SQUARED_HPP__
struct squared
{
void operator()(int&);
};
#endif // __SQUARED_HPP__
… a command such as nvc++ -stdpar -std=c++17 squared.cpp main.cpp
will fail to link due to an undefined reference to squared::operator()(int&)
. I’m using nvc++ from v21.9 of the HPC SDK on Ubuntu 20.10.
Thanks,
Paul