source: CIVL/examples/omp/dotProduct_orphan.c@ beab7f2

main test-branch
Last change on this file since beab7f2 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_orphan.c
3* DESCRIPTION:
4* OpenMP Example - Parallel region with an orphaned directive - C/C++ Version
5* This example demonstrates a dot product being performed by an orphaned
6* loop reduction construct. Scoping of the reduction variable is critical.
7* AUTHOR: Blaise Barney 5/99
8* LAST REVISED: 06/30/05
9******************************************************************************/
10/**
11* This program computes the dot product of two vectors. The parallel loop
12* construct is orphaned - it is contained in a subroutine outside the lexical
13* extent of the main program's parallel region.
14* Online source:
15* https://computing.llnl.gov/tutorials/openMP/samples/C/omp_orphan.c
16**/
17#include <omp.h>
18#include <stdio.h>
19#include <stdlib.h>
20#define VECLEN 100
21
22float a[VECLEN], b[VECLEN], sum;
23
24float dotprod ()
25{
26int i,tid;
27
28tid = omp_get_thread_num();
29#pragma omp for reduction(+:sum)
30 for (i=0; i < VECLEN; i++)
31 {
32 sum = sum + (a[i]*b[i]);
33 printf(" tid= %d i=%d\n",tid,i);
34 }
35}
36
37
38int main (int argc, char *argv[]) {
39int i;
40
41for (i=0; i < VECLEN; i++)
42 a[i] = b[i] = 1.0 * i;
43sum = 0.0;
44
45#pragma omp parallel
46 dotprod();
47
48printf("Sum = %f\n",sum);
49
50}
51
Note: See TracBrowser for help on using the repository browser.