Skip to content

Instantly share code, notes, and snippets.

@vzarytovskii
Created December 6, 2011 11:39
Show Gist options
  • Save vzarytovskii/1437898 to your computer and use it in GitHub Desktop.
Save vzarytovskii/1437898 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <complex>
#include <vector>
#include <omp.h>
using namespace std;
int main() {
int number_to = 1000000;
vector<int> primes;
primes.reserve(number_to/2);
#pragma omp parallel for schedule(static) num_threads(8)
for(int i=1;i<=number_to;i+=2) {
if (i < 2 || i % 5 == 0 || i % 2 == 0) continue;
if (i < 4) {
#pragma omp critical(dataupdate)
primes.push_back(i);
continue;
}
for(int j=3;j<i/2;j++) {
if(i % j == 0) {
break;
}
}
#pragma omp critical(dataupdate)
primes.push_back(i);
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment