This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/cuda/unioncpu2.cpp
2016-07-31 10:14:02 -05:00

69 lines
1.5 KiB
C++

#include <thrust/unique.h>
#include <thrust/distance.h>
#include <thrust/system/omp/execution_policy.h>
#include <iostream>
#include "union2.h"
int unircpu(int *res, int rows, int tipo, int **ret)
{
//cout << "En union = " << rows << " " << tipo << endl;
s2 *t2, *re2;
s3 *t3, *re3;
int nrows, *nres;
//int size;
switch(tipo)
{
case 1:
{
thrust::sort(thrust::omp::par, res, res + rows);
nres = thrust::unique(thrust::omp::par, res, res + rows);
nrows = thrust::distance(res, nres);
/*if(nrows < rows / 2)
{
size = nrows * tipo * sizeof(int);
nres = (int *)malloc(size);
memcpy(nres, res, size);
free(*ret);
*ret = nres;
}*/
return nrows;
}
case 2:
{
t2 = (s2*)res;
thrust::sort(thrust::omp::par, t2, t2 + rows, o2());
re2 = thrust::unique(thrust::omp::par, t2, t2 + rows, p2());
nrows = thrust::distance(t2, re2);
/*if(nrows < rows / 2)
{
size = nrows * tipo * sizeof(int);
nres = (int *)malloc(size);
memcpy(nres, res, size);
free(*ret);
*ret = nres;
}*/
return nrows;
}
case 3:
{
t3 = (s3*)res;
thrust::sort(thrust::omp::par, t3, t3 + rows, o3());
re3 = thrust::unique(thrust::omp::par, t3, t3 + rows, p3());
nrows = thrust::distance(t3, re3);
/*if(nrows < rows / 2)
{
size = nrows * tipo * sizeof(int);
nres = (int *)malloc(size);
memcpy(nres, res, size);
free(*ret);
*ret = nres;
}*/
return nrows;
}
}
return 0;
}