OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [libgomp/] [testsuite/] [libgomp.c/] [omp_reduction.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/******************************************************************************
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
#include <omp.h>
14
#include <stdio.h>
15
#include <stdlib.h>
16
 
17
int main (int argc, char *argv[]) {
18
 
19
int   i, n;
20
float a[100], b[100], sum;
21
 
22
/* Some initializations */
23
n = 100;
24
for (i=0; i < n; i++)
25
  a[i] = b[i] = i * 1.0;
26
sum = 0.0;
27
 
28
#pragma omp parallel for reduction(+:sum)
29
  for (i=0; i < n; i++)
30
    sum = sum + (a[i] * b[i]);
31
 
32
printf("   Sum = %f\n",sum);
33
 
34
  return 0;
35
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.