create-pl1-omp 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -1
- package/package.json +1 -1
- package/template/PL4/PL4.c +50 -0
package/index.js
CHANGED
|
@@ -13,7 +13,8 @@ async function run() {
|
|
|
13
13
|
{ title: 'All Programs', value: 'ALL' },
|
|
14
14
|
{ title: 'PL1 - Parallel Merge Sort (OpenMP)', value: 'PL1' },
|
|
15
15
|
{ title: 'PL2 - OpenMP Static Loop Scheduling', value: 'PL2' },
|
|
16
|
-
{ title: 'PL3 - Fibonacci Series using OpenMP Tasks', value: 'PL3' }
|
|
16
|
+
{ title: 'PL3 - Fibonacci Series using OpenMP Tasks', value: 'PL3' },
|
|
17
|
+
{ title: 'PL4 - Prime Number Finder (Reduction & Dynamic)', value: 'PL4' }
|
|
17
18
|
],
|
|
18
19
|
initial: 0,
|
|
19
20
|
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#include <stdio.h>
|
|
2
|
+
#include <stdlib.h>
|
|
3
|
+
#include <omp.h>
|
|
4
|
+
#include <math.h>
|
|
5
|
+
|
|
6
|
+
int is_prime(int num) {
|
|
7
|
+
if (num <= 1) return 0;
|
|
8
|
+
if (num == 2) return 1;
|
|
9
|
+
if (num % 2 == 0) return 0;
|
|
10
|
+
for (int i = 3; i <= sqrt(num); i += 2) {
|
|
11
|
+
if (num % i == 0) return 0;
|
|
12
|
+
}
|
|
13
|
+
return 1;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
int main() {
|
|
17
|
+
int n;
|
|
18
|
+
printf("Enter the upper limit (n) to find prime numbers: ");
|
|
19
|
+
scanf("%d", &n);
|
|
20
|
+
|
|
21
|
+
if (n < 2) {
|
|
22
|
+
printf("There are no prime numbers up to %d.\n", n);
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
printf("\nFinding prime numbers from 1 to %d...\n", n);
|
|
27
|
+
|
|
28
|
+
double start_time = omp_get_wtime();
|
|
29
|
+
int sequential_prime_count = 0;
|
|
30
|
+
for (int i = 1; i <= n; i++) {
|
|
31
|
+
if (is_prime(i)) sequential_prime_count++;
|
|
32
|
+
}
|
|
33
|
+
double time_seq = omp_get_wtime() - start_time;
|
|
34
|
+
printf("\nSequential: Found %d primes in %f seconds\n", sequential_prime_count, time_seq);
|
|
35
|
+
|
|
36
|
+
start_time = omp_get_wtime();
|
|
37
|
+
int parallel_prime_count = 0;
|
|
38
|
+
#pragma omp parallel for reduction(+:parallel_prime_count) schedule(dynamic)
|
|
39
|
+
for (int i = 1; i <= n; i++) {
|
|
40
|
+
if (is_prime(i)) parallel_prime_count++;
|
|
41
|
+
}
|
|
42
|
+
double time_par = omp_get_wtime() - start_time;
|
|
43
|
+
printf("Parallel: Found %d primes in %f seconds\n", parallel_prime_count, time_par);
|
|
44
|
+
|
|
45
|
+
if (time_par > 0 && time_seq > 0) {
|
|
46
|
+
printf("\nSpeedup: %.2fx\n", time_seq / time_par);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return 0;
|
|
50
|
+
}
|