Skip to content

Instantly share code, notes, and snippets.

@antonmks

antonmks/despace.cu

Last active Jan 20, 2017
Embed
What would you like to do?
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/remove.h>
#include <ctime>
#include <fstream>
#include <algorithm>
#include <cstdlib>
struct despace
{
__host__ __device__
bool operator()(const char x)
{
return (x == ' ' || x == '\n' || x == '\r');
}
};
int main(void)
{
thrust::host_vector<char> h_vec(1000000000); // 1GB of data
std::cout << "Generating data... " << std::endl;
std::generate(h_vec.begin(), h_vec.end(), rand);
std::cout << "Done generating data... " << std::endl;
thrust::device_vector<char> d_vec = h_vec;
std::cout << "despacing" << std::endl;
std::clock_t start1 = std::clock();
auto new_end = thrust::remove_if(d_vec.begin(), d_vec.end(), despace());
std::cout<< "remove time " << ( ( std::clock() - start1 ) / (double)CLOCKS_PER_SEC ) << std::endl;
std::cout << "New char count " << new_end - d_vec.begin() << std::endl;
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment