source: CIVL/examples/omp/c_pi.c@ 7d77e64

main test-branch
Last change on this file since 7d77e64 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: 3.0 KB
Line 
1/* ***********************************************************************
2 This program is part of the
3 OpenMP Source Code Repository
4
5 http://www.pcg.ull.es/ompscr/
6 e-mail: ompscr@etsii.ull.es
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 (LICENSE file) along with this program; if not, write to
20 the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 Boston, MA 02111-1307 USA
22
23 FILE: c_pi.c
24 VERSION: 1.0
25 DATE: May 2004
26 COMMENTS TO: sande@csi.ull.es
27 DESCRIPTION: Parallel implementation of PI generator using OpenMP
28 COMMENTS: The area under the curve y=4/(1+x*x) between 0 and 1 provides a way to compute Pi
29 The value of this integral can be approximated using a sum.
30 REFERENCES: http://en.wikipedia.org/wiki/Pi
31 http://nereida.deioc.ull.es/~llCoMP/examples/examples/pi/pi_description.html
32 BASIC PRAGMAS: parallel
33 USAGE: ./c_pi.par
34 INPUT: Default precision
35 OUTPUT: The value of PI
36 FILE FORMATS: -
37 RESTRICTIONS: -
38 REVISION HISTORY:
39**************************************************************************/
40//#include "OmpSCR.h"
41#include <omp.h>
42#include <stdio.h>
43
44
45#define DEFAULT_PREC 1000000 /* Default precision */
46#define NUM_ARGS 1
47#define NUM_TIMERS 1
48
49int main(int argc, char *argv[]) {
50 double PI25DT = 3.141592653589793238462643;
51 double local, w, total_time, pi;
52 long i,
53 N; /* Precision */
54 int NUMTHREADS;
55// char *PARAM_NAMES[NUM_ARGS] = {"Precision"};
56// char *DEFAULTS_VALUE[NUM_ARGS] = {"1000000"};
57// char *TIMERS_NAMES[NUM_TIMERS] = {"Total_time"};
58
59 /* Default: DEFAULT_PREC; */
60
61 NUMTHREADS = 1; //omp_get_num_threads();
62 //OSCR_init (NUMTHREADS, "Pi generator", "Param: precission", NUM_ARGS, PARAM_NAMES, DEFAULTS_VALUE , NUM_TIMERS, NUM_TIMERS, TIMERS_NAMES, argc, argv);
63 //N = OSCR_getarg_int(NUM_ARGS);
64 //OSCR_timer_start(0);
65 w = 1.0 / N;
66 pi = 0.0;
67/* #pragma omp parallel for default(shared) private(i, local)reduction(+:pi) schedule(static, 1) */
68#pragma omp parallel for default(shared) private(i, local)reduction(+:pi)
69 for(i = 0; i < N; i++) {
70 local = (i + 0.5) * w;
71 pi += 4.0 / (1.0 + local * local);
72 }
73 pi *= w;
74 //OSCR_timer_stop(0);
75 total_time = 1; //OSCR_timer_read(0);
76
77 //OSCR_report();
78 printf("\n \t# THREADS INTERVAL \tTIME (secs.) \tPI \t\t\tERROR\n");
79 printf("\t %d \t%10ld \t%14.6lf \t%1.20f\t%g\n", NUMTHREADS, N, total_time, pi, PI25DT-pi);
80 return 0;
81}
82
83/*
84 * vim:ts=2:sw=2:
85 */
86
Note: See TracBrowser for help on using the repository browser.