source: CIVL/examples/omp/dotProduct1.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/******************************************************************************
2* FILE: omp_reduction.c
3* DESCRIPTION:
4* OpenMP Example - Combined Parallel Loop Reduction - C/C++ Version
5* This example demonstrates a sum reduction within a combined parallel loop
6* construct. Notice that default data element scoping is assumed - there
7* are no clauses specifying shared or private variables. OpenMP will
8* automatically make loop index variables private within team threads, and
9* global variables shared.
10* AUTHOR: Blaise Barney 5/99
11* LAST REVISED: 04/06/05
12******************************************************************************/
13/**
14* This program computes the dot product of two vectors.
15* Online source:
16* https://computing.llnl.gov/tutorials/openMP/samples/C/omp_reduction.c
17**/
18#include <omp.h>
19#include <stdio.h>
20#include <stdlib.h>
21
22int main (int argc, char *argv[])
23{
24int i, n;
25float a[8], b[8], sum;
26
27/* Some initializations */
28n = 8;
29for (i=0; i < n; i++)
30 a[i] = b[i] = i * 1.0;
31sum = 0.0;
32
33#pragma omp parallel for reduction(+:sum)
34 for (i=0; i < n; i++){
35 sum = sum + (a[i] * b[i]);
36 printf("loop %d\n", i);
37 }
38
39printf(" Sum = %f\n",sum);
40
41}
Note: See TracBrowser for help on using the repository browser.