Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Cannot compile the OpenMP implementation of sort() with Visual Studio 2015 #817

Closed
tdelame opened this issue Jul 18, 2016 · 2 comments
Closed

Comments

@tdelame
Copy link

tdelame commented Jul 18, 2016

With Visual Studio 2015 and thrust version 1.8.3, it is impossible to compile to following code sample. I believe this is due to the implementation of OpenMP in Visual Studio. If this is confirmed by other users, it might be interesting to check which compiler is used in any OpenMP implementation of thrust functions. This way it would be possible to inform the user that this is a known bug and that CPP execution policy must be used instead with Visual Studio, at least for current versions of this compiler.

# include <thrust/sort.h>
# include <thrust/system/omp/execution_policy.h>
# include <chrono>
# include <random>
# include <vector>

double unit_random()
{
  static std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
  static std::uniform_real_distribution<double> distribution(double(0), double(1));
  return distribution(generator);
}

int main(int argc, char* argv[])
{
  constexpr size_t input_size = 100000;
  std::vector< double > input(input_size, 0);
  for ( size_t i = 0; i < input_size; ++i)
    input[i] = unit_random() * 1000;

  thrust::sort(thrust::omp::par, input.begin(), input.end());
  //of course, we get the same error for the following line compiled with /DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_OMP
  //thrust::sort( input.begin(), input.end());
  return 0;
}

Here is the compilation output in the Visual Studio 2015 console:

thrust/system/omp/detail/sort.inl(136): error C2146: syntax error: missing ';' before identifier 'nseg'
thrust/detail/sort.inl(83): note: see reference to function template instantiation 'void thrust::system::omp::detail::stable_sort<thrust::system::omp::detail::par_t,RandomAccessIterator,StrictWeakOrdering>(thrust::system::omp::detail::execution_policy<thrust::system::omp::detail::par_t> &,RandomAccessIterator,RandomAccessIterator,StrictWeakOrdering)' being compiled
  with
  [
    RandomAccessIterator=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<double>>>,
    StrictWeakOrdering=thrust::less<value_type>
  ]
thrust/system/detail/generic/sort.inl(63): note: see reference to function template instantiation 'void thrust::stable_sort<DerivedPolicy,RandomAccessIterator,StrictWeakOrdering>(const thrust::detail::execution_policy_base<DerivedPolicy> &,RandomAccessIterator,RandomAccessIterator,StrictWeakOrdering)' being compiled
  with
  [
      DerivedPolicy=thrust::system::omp::detail::par_t,
      RandomAccessIterator=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<double>>>,
      StrictWeakOrdering=thrust::less<value_type>
  ]
thrust/detail/sort.inl(56): note: see reference to function template instantiation 'void thrust::system::detail::generic::sort<Derived,RandomAccessIterator,StrictWeakOrdering>(thrust::execution_policy<Derived> &,RandomAccessIterator,RandomAccessIterator,StrictWeakOrdering)' being compiled
  with
  [
      Derived=thrust::system::omp::detail::par_t,
      RandomAccessIterator=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<double>>>,
      StrictWeakOrdering=thrust::less<value_type>
  ]
thrust/system/detail/generic/sort.inl(49): note: see reference to function template instantiation 'void thrust::sort<DerivedPolicy,RandomAccessIterator,thrust::less<value_type>>(const thrust::detail::execution_policy_base<DerivedPolicy> &,RandomAccessIterator,RandomAccessIterator,StrictWeakOrdering)' being compiled
  with
  [
      DerivedPolicy=thrust::system::omp::detail::par_t,
      RandomAccessIterator=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<double>>>,
      StrictWeakOrdering=thrust::less<value_type>
  ]
thrust/detail/sort.inl(41): note: see reference to function template instantiation 'void thrust::system::detail::generic::sort<Derived,RandomAccessIterator>(thrust::execution_policy<Derived> &,RandomAccessIterator,RandomAccessIterator)' being compiled
  with
  [
      Derived=thrust::system::omp::detail::par_t,
      RandomAccessIterator=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<double>>>
  ]
windows_cuda_thrust_error.cc(24): note: see reference to function template instantiation 'void thrust::sort<DerivedPolicy,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<double>>>>(const thrust::detail::execution_policy_base<DerivedPolicy> &,RandomAccessIterator,RandomAccessIterator)' being compiled
  with
  [
      DerivedPolicy=thrust::system::omp::detail::par_t,
      RandomAccessIterator=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<double>>>
  ]
thrust/system/omp/detail/sort.inl(136): error C2275: 'IndexType': illegal use of this type as an expression
thrust/system/omp/detail/sort.inl(113): note: see declaration of 'IndexType'
thrust/system/omp/detail/sort.inl(136): error C2065: 'nseg': undeclared identifier
thrust/system/omp/detail/sort.inl(142): error C2065: 'nseg': undeclared identifier
thrust/system/omp/detail/sort.inl(159): error C2065: 'nseg': undeclared identifier
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
jaredhoberock added a commit to jaredhoberock/thrust that referenced this issue Jul 23, 2016
@jaredhoberock
Copy link
Contributor

Thanks for the report, @tdelame.

@egaburov: I think I have a workaround in my branch issue-817. I'd like to schedule this for version 1.8.3 if you think we can fit it in. Otherwise, I'll push it to master. What do you think?

@3gx
Copy link
Contributor

3gx commented Jul 23, 2016

Sounds good, we will target this bugfix for 1.8.3. I'll use issue-817 branch for the integration purpose. I plan to get it done by end of the next week at the latest, and will submit PR to 1.8.3 then.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants