Created
December 6, 2011 11:39
-
-
Save vzarytovskii/1437898 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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