Tutorial by Examples

#include <stdio.h> #include <math.h> #include <omp.h> #define N 1000000 int main() { double sum = 0; double tbegin = omp_get_wtime(); #pragma omp parallel for reduction( +: sum ) for ( int i = 0; i < N; i++ ) { sum += cos( i ); } ...
program typical_loop use omp_lib implicit none integer, parameter :: N = 1000000, kd = kind( 1.d0 ) real( kind = kd ) :: sum, tbegin, wtime integer :: i sum = 0 tbegin = omp_get_wtime() !$omp parallel do reduction( +: sum ) do i = 1, N sum = ...
On a 8 cores Linux machine using GCC version 4.4, the C codes can be compiled and run the following way: $ gcc -std=c99 -O3 -fopenmp loop.c -o loopc -lm $ OMP_NUM_THREADS=1 ./loopc Computing 1000000 cosines and summing them with 1 threads took 0.095832s $ OMP_NUM_THREADS=2 ./loopc Computing 100...
void parallelAddition (unsigned N, const double *A, const double *B, double *C) { unsigned i; #pragma omp parallel for shared (A,B,C,N) private(i) schedule(static) for (i = 0; i < N; ++i) { C[i] = A[i] + B[i]; } } This example adds two vector (A and B into...

Page 1 of 1