Hello,
I am trying to apply intersect by key in 2 vectors. I plan to remove from these two vectors the values with -1 in the key vector that is d_intersected_triangles. But after I intersect with key I get null vectors of the same as the original vectors…
Thank you in advance,
Rafael Scatena
The struct:
struct diff_minus_1{__host__ __device__ bool operator()(int64_t x)
const {return x != convertToInt64(-1);}};
The Program:
thrust::device_ptr<int64_t> dev_ptr(d_intersected_triangles);
// Create KeysA: this will contain the full data, including -1 values
thrust::device_vector<int64_t> KeysA(dev_ptr, dev_ptr + maxTriangles); // Full vector
for (size_t i = 0; i < 50; ++i) {std::cout << KeysA[i] << std::endl;}
// Create KeysB: remove all -1 values from KeysA
// First, create a device vector to hold KeysB with enough space
thrust::device_vector<int64_t> KeysB(maxTriangles);
auto new_end = thrust::copy_if(thrust::device, KeysA.begin(), KeysA.end(), KeysB.begin(),diff_minus_1());
// Resize KeysB to match the number of valid entries
KeysB.resize(new_end - KeysB.begin()); size_t keysB_size = KeysB.size();
std::cout << "PRISMAMESH: Thrust Remove Ok: "<< KeysB.size()<< std::endl;
thrust::device_ptr<Point> dev_ptr2(d_intersection_point); thrust::device_ptr<double> dev_ptr3(d_distance);
thrust::device_vector<Point> device_intersections(dev_ptr2,dev_ptr2+maxTriangles);
thrust::device_vector<double> device_distances(dev_ptr3,dev_ptr3+maxTriangles);
for (size_t i = 0; i < 50; ++i) {const Point& p = device_intersections[i];
std::cout << KeysA[i] << " | ("<< p.x << ", " << p.y << ", " << p.z << ") | "<< device_distances[i] << std::endl;}
thrust::device_vector<int64_t> keys_result(maxTriangles); thrust::device_vector<Point> result_intersections(maxTriangles); thrust::device_vector<double> result_distances(maxTriangles);
thrust::set_intersection_by_key(thrust::device, KeysA.begin(), KeysA.end(),KeysB.begin(), KeysB.end() device_intersections.begin(),keys_result.begin(), result_intersections.begin());
thrust::set_intersection_by_key(thrust::device, KeysA.begin(),KeysA.end(), KeysB.begin(),KeysB.end(),
device_distances.begin(),keys_result.begin(), result_distances.begin());
size_t min_size = std::min({keys_result.size(), result_intersections.size(), result_distances.size()});
std::cout << "PRISMAMESH: Thrust Intersection Ok: "<< result_intersections.size()<< std::endl;
for (size_t i = 0; i < 50; ++i) {const Point& p = result_intersections[i];
std::cout << keys_result[i] << " | ("<< p.x << ", " << p.y << ", " << p.z << ") | "<< result_distances[i] << std::endl;}
output 1:
488571
473370
488148
473979
352371
503606
488410
352218
352241
352249
473570
352268
352285
473838
472090
486850
352249
474553
136572
474980
489238
489588
134266
133951
135853
485352
497440
136036
135871
482861
500041
135062
508395
136451
485826
500615
501683
486741
133980
135062
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
output 2:
PRISMAMESH: Thrust Remove Ok: 40
488571 | (22.4945, 23.2413, 1.25) | 23.2413
473370 | (22.4945, 22.6263, 1.25) | 22.6263
488148 | (22.4945, 22.6263, 1.25) | 22.6263
473979 | (22.4945, 23.4171, 1.25) | 23.4171
352371 | (22.4945, 23.3878, 1.25) | 23.3878
503606 | (22.4945, 23.4171, 1.25) | 23.4171
488410 | (22.4945, 22.9777, 1.25) | 22.9777
352218 | (22.4945, 23.2413, 1.25) | 23.2413
352241 | (22.4945, 23.3878, 1.25) | 23.3878
352249 | (22.4945, 22.6977, 1.25) | 22.6977
473570 | (22.4945, 22.9777, 1.25) | 22.9777
352268 | (22.4945, 22.9857, 1.25) | 22.9857
352285 | (22.4945, 23.2413, 1.25) | 23.2413
473838 | (22.4945, 23.2413, 1.25) | 23.2413
472090 | (22.4945, 10.1489, 1.25) | 10.1489
486850 | (22.4945, 10.1489, 1.25) | 10.1489
352249 | (22.4945, 22.6977, 1.25) | 22.6977
474553 | (22.4945, 24.3836, 1.25) | 24.3836
136572 | (22.4945, 24.3836, 1.25) | 24.3836
474980 | (22.4945, 24.9987, 1.25) | 24.9987
489238 | (22.4945, 24.3836, 1.25) | 24.3836
489588 | (22.4945, 24.9987, 1.25) | 24.9987
134266 | (22.4945, 26.8537, 1.25) | 26.8537
133951 | (22.4945, 24.3836, 1.25) | 24.3836
135853 | (22.4945, 27.9423, 1.25) | 27.9423
485352 | (22.4945, 30.0951, 1.25) | 30.0951
497440 | (22.4945, 28.7771, 1.25) | 28.7771
136036 | (22.4945, 28.7185, 1.25) | 28.7185
135871 | (22.4945, 28.0302, 1.25) | 28.0302
482861 | (22.4945, 28.7771, 1.25) | 28.7771
500041 | (22.4945, 30.0951, 1.25) | 30.0951
135062 | (22.4945, 30.0686, 1.25) | 30.0686
508395 | (22.4945, 27.1076, 1.25) | 27.1076
136451 | (22.4945, 30.6443, 1.25) | 30.6443
485826 | (22.4945, 30.6223, 1.25) | 30.6223
500615 | (22.4945, 30.6223, 1.25) | 30.6223
501683 | (22.4945, 35.9824, 1.25) | 35.9824
486741 | (22.4945, 35.9824, 1.25) | 35.9824
133980 | (22.4945, 24.9243, 1.25) | 24.9243
135062 | (22.4945, 30.0686, 1.25) | 30.0686
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
-1 | (0, 0, 0) | 0
output 3:
PRISMAMESH: Thrust Intersection Ok: 3131877
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0
0 | (0, 0, 0) | 0