push_back object on thrust::device_vector

-1

I was trying to use thrust::device_vector to store a struct and it worked fine until I called push_back() twice and the program crashed. The program also crashed when I used resize().

Here is the code I am using, I am compiling it with nvcc:

#include <iostream>
#include <thrust/device_vector.h>

using namespace thrust;
using namespace std;

struct Test
{
  int value;
  __device__ __host__
  Test() {
    value = 0;
  }
  __device__ __host__
  ~Test() {}
};

int main() {
  device_vector<Test> test_d = device_vector<Test>();

  cout << "First" << endl;
  test_d.push_back(Test());

  cout << "second" << endl;
  test_d.push_back(Test());

  cout << "done" << endl;
  return 0;
}

the output of the program gives me this:

First

second

nvcc error : '.\"a.exe"' died with status 0xC0000409

Is this program correct, as in does it crash on other machines or am I missing something?

c++
cuda
thrust
asked on Stack Overflow Jun 6, 2018 by Glacier11 • edited Jun 6, 2018 by Glacier11

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0