Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rharriso
Created October 14, 2018 22:45
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 rharriso/3b6027b48547e540b469ab12b17d304c to your computer and use it in GitHub Desktop.
Save rharriso/3b6027b48547e540b469ab12b17d304c to your computer and use it in GitHub Desktop.
Looking at Thrust: main-cpu.cpp
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <vector>
int main () {
int N = 8000 * 8000; // 800px x 800px image
int iterations = 10;
int size = N*sizeof(float);
float *x, *y, *output;
x = (float *) malloc(size);
y = (float *) malloc(size);
output = (float *) malloc(size);
for (int i = 0; i < N; i++) {
x[i] = ((float) std::rand()) / (float) RAND_MAX;
y[i] = ((float) std::rand()) / (float) RAND_MAX;
}
// initialize random arrays
for (int blerp = 0; blerp < iterations; blerp++) {
for (int i = 0; i < N; i++) {
output[i] = x[i] + y[i];
}
}
free(x);
free(y);
free(output);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment