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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [libgomp/] [testsuite/] [libgomp.c/] [omp_orphan.c] - Diff between revs 273 and 338

Only display areas with differences | Details | Blame | View Log

Rev 273 Rev 338
/******************************************************************************
/******************************************************************************
* FILE: omp_orphan.c
* FILE: omp_orphan.c
* DESCRIPTION:
* DESCRIPTION:
*   OpenMP Example - Parallel region with an orphaned directive - C/C++ Version
*   OpenMP Example - Parallel region with an orphaned directive - C/C++ Version
*   This example demonstrates a dot product  being performed by an orphaned
*   This example demonstrates a dot product  being performed by an orphaned
*   loop reduction construct.  Scoping of the reduction variable is critical.
*   loop reduction construct.  Scoping of the reduction variable is critical.
* AUTHOR: Blaise Barney  5/99
* AUTHOR: Blaise Barney  5/99
* LAST REVISED: 04/06/05
* LAST REVISED: 04/06/05
******************************************************************************/
******************************************************************************/
#include <omp.h>
#include <omp.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#define VECLEN 100
#define VECLEN 100
 
 
float a[VECLEN], b[VECLEN], sum;
float a[VECLEN], b[VECLEN], sum;
 
 
float dotprod ()
float dotprod ()
{
{
int i,tid;
int i,tid;
 
 
tid = omp_get_thread_num();
tid = omp_get_thread_num();
#pragma omp for reduction(+:sum)
#pragma omp for reduction(+:sum)
  for (i=0; i < VECLEN; i++)
  for (i=0; i < VECLEN; i++)
    {
    {
    sum = sum + (a[i]*b[i]);
    sum = sum + (a[i]*b[i]);
    printf("  tid= %d i=%d\n",tid,i);
    printf("  tid= %d i=%d\n",tid,i);
    }
    }
 
 
return(sum);
return(sum);
}
}
 
 
 
 
int main (int argc, char *argv[])
int main (int argc, char *argv[])
{
{
int i;
int i;
 
 
for (i=0; i < VECLEN; i++)
for (i=0; i < VECLEN; i++)
  a[i] = b[i] = 1.0 * i;
  a[i] = b[i] = 1.0 * i;
sum = 0.0;
sum = 0.0;
 
 
#pragma omp parallel
#pragma omp parallel
  sum = dotprod();
  sum = dotprod();
 
 
printf("Sum = %f\n",sum);
printf("Sum = %f\n",sum);
 
 
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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