This repository has been archived on 2022-10-18. You can view files and clone it, but cannot push or open issues or pull requests.
HPC/Project2/Project2-code/loop-dependencies/recur_omp.c

35 lines
786 B
C
Raw Normal View History

2022-10-18 12:39:50 +00:00
#include "walltime.h"
#include <math.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int N = 2000000000;
double up = 1.00000001;
double Sn = 1.00000001;
int n;
/* allocate memory for the recursion */
double *opt = (double *)malloc((N + 1) * sizeof(double));
if (opt == NULL)
die("failed to allocate problem size");
double time_start = wall_time();
// TODO: YOU NEED TO PARALLELIZE THIS LOOP
for (n = 0; n <= N; ++n) {
opt[n] = Sn;
Sn *= up;
}
printf("Parallel RunTime : %f seconds\n", wall_time() - time_start);
printf("Final Result Sn : %.17g \n", Sn);
double temp = 0.0;
for (n = 0; n <= N; ++n) {
temp += opt[n] * opt[n];
}
printf("Result ||opt||^2_2 : %f\n", temp / (double)N);
printf("\n");
return 0;
}