source: CIVL/examples/omp/c_lu.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 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.3 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
23FILE: c_lu.c
24VERSION: 1.0
25DATE:
26AUTHOR: Arturo González-Escribano
27COMMENTS TO: arturo@infor.uva.es
28DESCRIPTION:
29 LU reduction of a 2D dense matrix
30
31COMMENTS:
32REFERENCES:
33BASIC PRAGMAS: parallel-for (stride scheduling)
34USAGE: ./c_lu.par <size>
35INPUT: The matrix has fixed innitial values:
36 M[i][j] = 1.0 iff (i==j)
37 M[i][j] = 1.0 + (i*numColums)+j iff (i!=j)
38
39OUTPUT: Compile with -DDEBUG to see final matrix values
40FILE FORMATS:
41RESTRICTIONS:
42REVISION HISTORY:
43**************************************************************************/
44#include <omp.h>
45
46#include<stdio.h>
47#include<stdlib.h>
48//#include<OmpSCR.h>
49
50#define SIZE 10
51
52/* PROTOYPES */
53void lu(int, int);
54
55
56/* MAIN: PROCESS PARAMETERS */
57int main(int argc, char *argv[]) {
58int nthreads, size;
59//char *argNames[1] = { "size" };
60//char *defaultValues[1] = { "500" };
61//char *timerNames[1] = { "EXE_TIME" };
62
63nthreads = 1; // omp_get_num_threads();
64//OSCR_init( nthreads,
65// "LU reduction of a dense matrix.",
66// NULL,
67// 1,
68// argNames,
69// defaultValues,
70// 1,
71// 1,
72// timerNames,
73// argc,
74// argv );
75
76/* 1. GET PARAMETERS */
77size = SIZE; //OSCR_getarg_int(1);
78
79/* 2. CALL COMPUTATION */
80lu(nthreads, size);
81
82/* 3. REPORT */
83//OSCR_report();
84
85
86return 0;
87}
88
89
90/*
91* LU FORWARD REDUCTION
92*/
93void lu(int nthreads, int size) {
94/* DECLARE MATRIX AND ANCILLARY DATA STRUCTURES */
95double **M;
96double **L;
97
98/* VARIABLES */
99int i,j,k;
100
101/* 0. ALLOCATE MATRICES MEMORY */
102M = (double **)calloc(size, sizeof(double *));
103L = (double **)calloc(size, sizeof(double *));
104for (i=0; i<size; i++) {
105 M[i] = (double *)calloc(size, sizeof(double));
106 L[i] = (double *)calloc(size, sizeof(double));
107 }
108
109/* 1. INITIALIZE MATRIX */
110for (i=0; i<size; i++) {
111 for (j=0; j<size; j++) {
112 if (i==j) M[i][j]=1.0;
113 else M[i][j]=1.0+(i*size)+j;
114 L[i][j]=0.0;
115 }
116 }
117
118/* 3. START TIMER */
119//OSCR_timer_start(0);
120
121/* 4. ITERATIONS LOOP */
122for(k=0; k<size-1; k++) {
123
124 /* 4.1. PROCESS ROWS IN PARALLEL, DISTRIBUTE WITH nthreads STRIDE */
125#pragma omp parallel for default(none) shared(M,L,size,k) private(i,j) schedule(static,1)
126 for (i=k+1; i<size; i++) {
127 /* 4.1.1. COMPUTE L COLUMN */
128 L[i][k] = M[i][k] / M[k][k];
129
130 /* 4.1.2. COMPUTE M ROW ELEMENTS */
131 for (j=k+1; j<size; j++)
132 M[i][j] = M[i][j] - L[i][k]*M[k][j];
133 }
134
135/* 4.2. END ITERATIONS LOOP */
136 }
137
138
139/* 5. STOP TIMER */
140//OSCR_timer_stop(0);
141
142/* 6. WRITE MATRIX (DEBUG) */
143#ifdef DEBUG
144#include "debug_ML.c"
145#endif
146
147/* 7. END */
148}
149
Note: See TracBrowser for help on using the repository browser.