-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprime_parallel_soe.c
More file actions
54 lines (48 loc) · 912 Bytes
/
prime_parallel_soe.c
File metadata and controls
54 lines (48 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* =====================================================================================
*
* Filename: prime_op.c
*
* Description:
*
* Version: 1.0
* Created: Wednesday 28 May 2014 04:49:52 IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include<stdio.h>
#include<math.h>
#include<omp.h>
#define N 10000001
int n=10000001;
int a[N];
void mark(int i)
{int j;
//printf("%d ------\n",i);
#pragma omp parallel for private(j)
for(j=i+i;j<=n-1;j+=i)
{//printf("%d ",j);
a[j]=1;
}
}
int main()
{int i;
//for(i=0;i<=1000;i++){
//printf("%d ",a[i]);
//}
//printf("%d")
int cnt=0;
for(i=2;i<=sqrt(n-1);i++)
{ if (a[i]==0)
mark(i);
}
for(i=2;i<=n-1;i++){
if (a[i]==0){cnt++;
}}
printf("%d",cnt);
}