Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 7440af47 authored by thierry's avatar thierry
Browse files

Lectures for 9/11/2021

parent e880d821
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
double f(double x)
{
return (4.0 / (1.0 + x*x));
}
void loop(int n, double* C, double* A, double alpha, double* B, double beta)
{
for (int i = 0; i < n; i++)
C[i] = alpha * A[i] + beta * B[i];
}
void loop(int n, double* C, double* A, double alpha, double* B, double beta)
{
#pragma GCC ivdep
for (int i = 0; i < n; i++)
C[i] = alpha * A[i] + beta * B[i];
}
void loop(int n, double* restrict C, double* restrict A, double alpha, double* restrict B, double beta)
{
for (int i = 0; i < n; i++)
C[i] = alpha * A[i] + beta * B[i];
}
void loop(int n, double* C, double* A, double alpha, double* B, double beta)
{
#pragma omp simd safelen(16) simdlen(8) aligned(C,A,B:32)
for (int i = 0; i < n; i++)
C[i] = alpha * A[i] + beta * B[i];
}
double dotprod(int n, double* A, double* B)
{
double retval = 0;
#pragma omp simd reduction(+: retval)
for (int i = 0; i < n; i++)
retval += A[i] * B[i];
return retval;
}
int loop(int n, double* A, double* B)
{
#pragma omp simd safelen(2)
for(int i=2 ; i < n ; i++)
{
A[i]=A[i-2]+B[i];
}
}
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
double f(double x);
int main(int argc, char** argv)
{
int n = atoi(argv[1]);
double fH = 1.0/((double)n);
double fX, fSum;
int i;
for (int iter=0; iter<4; ++iter)
{
double t0 = omp_get_wtime();
for (i = 0; i < n; i++)
{
fX = fH * ((double)i + 0.5);
fSum += f(fX);
}
double t1 = omp_get_wtime();
printf("Pi: %2.15f\n", fH * fSum);
printf("Time: %f\n", t1-t0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment