Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <omp.h>
- #include <cmath>
- #include <time.h>
- #include <stdio.h>
- #define MAXSIZE 3000
- void create_array(double array[][MAXSIZE], int n) {
- for (int i=0; i<n; i++) {
- //std::cout << omp_get_thread_num() << std::endl;
- for (int j = 0; j < n; j++) {
- array[i][j] = i*(atan(j) +exp(-(i+j)));
- }
- }
- }
- void create_array_parallel(double array[][MAXSIZE], int n) {
- #pragma omp parallel for
- for (int i=0; i<n; i++) {
- //std::cout << omp_get_thread_num() << std::endl;
- for (int j = 0; j < n; j++) {
- array[i][j] = i*(atan(j) +exp(-(i+j)));
- }
- }
- }
- double array[MAXSIZE][MAXSIZE];
- int main() {
- double start, finish, time_single_thread, time_multi_thread;
- start = omp_get_wtime();
- create_array(array, MAXSIZE);
- finish = omp_get_wtime();
- time_single_thread = finish - start;
- printf("Total runtime with single thread = %lg\n", time_single_thread);
- start = omp_get_wtime();
- create_array_parallel(array, MAXSIZE);
- finish = omp_get_wtime();
- time_multi_thread = finish - start;
- printf("Total runtime with multiple threads = %lg\n", time_multi_thread);
- printf("Speed up = %lg\n", time_single_thread / time_multi_thread);
- printf("Efficiency = %lg\n", time_single_thread / time_multi_thread / 2);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement