gcc -fopenmp -lm main.c
Created
February 1, 2020 16:10
-
-
Save abel0b/772e22d0d22319093ce2e0d4f78f301d to your computer and use it in GitHub Desktop.
calculcate power 3/2
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 <math.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <omp.h> | |
#define N 1000000 | |
// Compare 3/2 power calculation | |
int main() { | |
float start, end; | |
int i; | |
int a = 42; | |
float ret; | |
start = omp_get_wtime(); | |
for(i=0;i<N;i++) { | |
ret = pow(a, 3.0/2.0); | |
} | |
end = omp_get_wtime(); | |
printf("POW: %f in %fs\n", ret, end-start); | |
start = omp_get_wtime(); | |
for(i=0;i<N;i++) { | |
ret = sqrtf(a*a*a); | |
} | |
end = omp_get_wtime(); | |
printf("SQRT: %f in %fs\n", ret, end-start); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment