Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
seqGaussSeidel2D.c
Go to the documentation of this file.
1 /*
2 * seqGaussSeidel2D.c
3 * Stencil code: Gauss-Seidel 2D for the heat equation.
4 * Sequential basic code
5 *
6 * v1.0
7 * (c) 2013-2015, Arturo Gonzalez-Escribano
8 */
9 
10 /*
11  * <license>
12  *
13  * Hitmap v1.2
14  *
15  * This software is provided to enhance knowledge and encourage progress in the scientific
16  * community. It should be used only for research and educational purposes. Any reproduction
17  * or use for commercial purpose, public redistribution, in source or binary forms, with or
18  * without modifications, is NOT ALLOWED without the previous authorization of the copyright
19  * holder. The origin of this software must not be misrepresented; you must not claim that you
20  * wrote the original software. If you use this software for any purpose (e.g. publication),
21  * a reference to the software package and the authors must be included.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY
24  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
26  * THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Copyright (c) 2007-2015, Trasgo Group, Universidad de Valladolid.
34  * All rights reserved.
35  *
36  * More information on http://trasgo.infor.uva.es/
37  *
38  * </license>
39 */
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 
44 int main(int argc, char *argv[]) {
45  if (argc < 4 ) {
46  fprintf( stderr, "Usage: %s <rows> <columns> <numIter>\n", argv[0] );
47  exit( EXIT_FAILURE );
48  }
49  int ROWS = atoi( argv[1] );
50  int COLS = atoi( argv[2] );
51  int STAGES = atoi( argv[3] );
52 
53  double mat[ROWS][COLS];
54  int i,j;
55 
56  // Init
57  for ( i=0; i<ROWS; i++ )
58  for ( j=0; j<COLS; j++ )
59  mat[i][j] = 0.0;
60 
61  for ( i=0; i<ROWS; i++ ) {
62  mat[i][0] = 3;
63  mat[i][COLS-1] = 4;
64  }
65 
66  for ( j=0; j<COLS; j++ ) {
67  mat[0][j] = 1;
68  mat[ROWS-1][j] = 2;
69  }
70 
71  // Compute
72  int stage;
73  for ( stage=0; stage<STAGES; stage++ ) {
74  // Compute iteration
75  for ( i=1; i<ROWS-1; i++ )
76  for ( j=1; j<COLS-1; j++ )
77  mat[i][j] = ( mat[i-1][j] + mat[i+1][j] + mat[i][j-1] + mat[i][j+1] ) / 4;
78  }
79 
80  // Write
81  for ( i=0; i<ROWS; i++ )
82  for ( j=0; j<COLS; j++ )
83  printf("%014.4lf\n", mat[i][j] );
84 
85  // End
86  return 0;
87 }
int main(int argc, char *argv[])
Definition: cannonAsync.c:62