Skip to content

Instantly share code, notes, and snippets.

@antonmks
Last active January 20, 2017 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonmks/17e0c711d41fb07d1b6f3ada3f5f29ee to your computer and use it in GitHub Desktop.
Save antonmks/17e0c711d41fb07d1b6f3ada3f5f29ee to your computer and use it in GitHub Desktop.
#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