Skip to content

Commit fcba590

Browse files
authored
fix #34, homogenization of the comment in the c file and yaml file (#36)
* fix homogenization of the comment in the c file and yaml file * fix #34, typo
1 parent e033e19 commit fcba590

31 files changed

+255
-127
lines changed

ex1.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <time.h>
3030

3131
#include <paraconf.h>
32+
// load the PDI header
3233
#include <pdi.h>
3334

3435
// size of the local data as [HEIGHT, WIDTH] including the number of ghost layers
@@ -53,7 +54,7 @@ double source1[4]={0.4, 0.4, 0.2, 100};
5354
double source2[4]={0.7, 0.8, 0.1, 200};
5455
// the order of the coordinates of the center (XX,YY) is inverted in the vector
5556

56-
/** Initialize all the data to 0, with the exception of a given cell
57+
/** Initialize all the data to 0, with the exception of each cells
5758
* whose center (cpos_x,cpos_y) is inside of the disks
5859
* defined by source1 or source2
5960
* \param[out] dat the local data to initialize

ex10.c

+22-9
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,31 @@
3232
// load the PDI header
3333
#include <pdi.h>
3434

35-
/// size of the local data as [HEIGHT, WIDTH] including ghosts & boundary constants
35+
// size of the local data as [HEIGHT, WIDTH] including the number of ghost layers
36+
// for communications or boundary conditions
3637
int dsize[2];
3738

38-
/// 2D size of the process grid as [HEIGHT, WIDTH]
39+
// 2D size of the process grid as [HEIGHT, WIDTH]
3940
int psize[2];
4041

41-
/// 2D rank of the local process in the process grid as [YY, XX]
42+
// 2D rank of the local process in the process grid as [YY, XX]
4243
int pcoord[2];
4344

44-
/// the alpha coefficient used in the computation
45+
// the alpha coefficient used in the computation
4546
double alpha;
4647

4748
double L=1.0;
49+
// definition of the source
50+
// the source corresponds to a disk of an uniform value
51+
// source1: center=(0.4,0.4), radius=0.2 and value=100
4852
double source1[4]={0.4, 0.4, 0.2, 100};
53+
// source2: center=(0.8,0.7), radius=0.1 and value=200
4954
double source2[4]={0.7, 0.8, 0.1, 200};
55+
// the order of the coordinates of the center (XX,YY) is inverted in the vector
5056

51-
/** Initialize the data all to 0 except for the left border (XX==0) initialized to 1 million
57+
/** Initialize all the data to 0, with the exception of each cells
58+
* whose center (cpos_x,cpos_y) is inside of the disks
59+
* defined by source1 or source2
5260
* \param[out] dat the local data to initialize
5361
*/
5462
void init(double dat[dsize[0]][dsize[1]])
@@ -58,14 +66,19 @@ void init(double dat[dsize[0]][dsize[1]])
5866
double dx = L / ((dsize[1]-2) *psize[1]) ;
5967

6068
double cpos_x,cpos_y;
69+
double square_dist1, square_dist2;
6170
for(int yy=0; yy<dsize[0];++yy) {
6271
cpos_y=(yy+pcoord[0]*(dsize[0]-2))*dy-0.5*dy;
6372
for(int xx=0; xx<dsize[1];++xx) {
6473
cpos_x=(xx+pcoord[1]*(dsize[1]-2))*dx-0.5*dx;
65-
if((cpos_y-source1[0])*(cpos_y-source1[0]) + (cpos_x-source1[1])*(cpos_x-source1[1]) <= source1[2]*source1[2]) {
74+
square_dist1 = ( cpos_y-source1[0] ) * ( cpos_y-source1[0] )
75+
+ ( cpos_x-source1[1] ) * ( cpos_x-source1[1] );
76+
if (square_dist1 <= source1[2] * source1[2]) {
6677
dat[yy][xx] = source1[3];
6778
}
68-
if((cpos_y-source2[0])*(cpos_y-source2[0]) + (cpos_x-source2[1])*(cpos_x-source2[1]) <= source2[2]*source2[2]) {
79+
square_dist2 = ( cpos_y-source2[0] ) * ( cpos_y-source2[0] )
80+
+ ( cpos_x-source2[1] ) * ( cpos_x-source2[1] );
81+
if (square_dist2 <= source2[2] * source2[2]) {
6982
dat[yy][xx] = source2[3];
7083
}
7184
}
@@ -90,7 +103,7 @@ void iter(double cur[dsize[0]][dsize[1]], double next[dsize[0]][dsize[1]])
90103
}
91104
}
92105

93-
/** Exchanges ghost values with neighbours
106+
/** Exchange ghost values with neighbours
94107
* \param[in] cart_comm the MPI communicator with all processes organized in a 2D Cartesian grid
95108
* \param[in] cur the local data at the current time-step whose ghosts need exchanging
96109
*/
@@ -170,7 +183,7 @@ int main( int argc, char* argv[] )
170183
assert(global_size[1]%psize[1]==0);
171184
assert(psize[1]*psize[0] == psize_1d);
172185

173-
// compute the local data-size with space for ghosts and boundary constants
186+
// compute the local data-size (the number of ghost layers is 2 for each coordinate)
174187
dsize[0] = global_size[0]/psize[0] + 2;
175188
dsize[1] = global_size[1]/psize[1] + 2;
176189

ex10.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# the alpha parameter
22
alpha: 0.125
3-
# global data-size (excluding spacer for boundary conditions or ghosts)
3+
# global data-size (excluding the number of ghost layers for boundary conditions)
44
global_size: { height: 60, width: 12 }
55
# degree of parallelism (number of blocks in each dimension)
66
parallelism: { height: 2, width: 2 }

ex11.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void compute_integral(void)
127127
}
128128

129129

130-
/** Initialize all the data to 0, with the exception of a given cell
130+
/** Initialize all the data to 0, with the exception of each cells
131131
* whose center (cpos_x,cpos_y) is inside of the disks
132132
* defined by source1 or source2
133133
* \param[out] dat the local data to initialize

ex12.c

+25-15
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,27 @@
3333
// load the PDI header
3434
#include <pdi.h>
3535

36-
/// size of the local data as [HEIGHT, WIDTH] including ghosts & boundary constants
36+
// size of the local data as [HEIGHT, WIDTH] including the number of ghost layers
37+
// for communications or boundary conditions
3738
int dsize[2];
3839

39-
/// 2D size of the process grid as [HEIGHT, WIDTH]
40+
// 2D size of the process grid as [HEIGHT, WIDTH]
4041
int psize[2];
4142

42-
/// 2D rank of the local process in the process grid as [YY, XX]
43+
// 2D rank of the local process in the process grid as [YY, XX]
4344
int pcoord[2];
4445

45-
/// the alpha coefficient used in the computation
46+
// the alpha coefficient used in the computation
4647
double alpha;
4748

4849
double L=1.0;
50+
// definition of the source
51+
// the source corresponds to a disk of an uniform value
52+
// source1: center=(0.4,0.4), radius=0.2 and value=100
4953
double source1[4]={0.4, 0.4, 0.2, 100};
54+
// source2: center=(0.8,0.7), radius=0.1 and value=200
5055
double source2[4]={0.7, 0.8, 0.1, 200};
56+
// the order of the coordinates of the center (XX,YY) is inverted in the vector
5157

5258
FILE *pFile2=NULL;
5359

@@ -77,7 +83,9 @@ void close_file(void)
7783
fclose(pFile2);
7884
}
7985

80-
/** Initialize the data all to 0 except for the left border (XX==0) initialized to 1 million
86+
/** Initialize all the data to 0, with the exception of each cells
87+
* whose center (cpos_x,cpos_y) is inside of the disks
88+
* defined by source1 or source2
8189
* \param[out] dat the local data to initialize
8290
*/
8391
void init(double dat[dsize[0]][dsize[1]])
@@ -87,14 +95,19 @@ void init(double dat[dsize[0]][dsize[1]])
8795
double dx = L / ((dsize[1]-2) *psize[1]) ;
8896

8997
double cpos_x,cpos_y;
98+
double square_dist1, square_dist2;
9099
for(int yy=0; yy<dsize[0];++yy) {
91100
cpos_y=(yy+pcoord[0]*(dsize[0]-2))*dy-0.5*dy;
92101
for(int xx=0; xx<dsize[1];++xx) {
93102
cpos_x=(xx+pcoord[1]*(dsize[1]-2))*dx-0.5*dx;
94-
if((cpos_y-source1[0])*(cpos_y-source1[0]) + (cpos_x-source1[1])*(cpos_x-source1[1]) <= source1[2]*source1[2]) {
103+
square_dist1 = ( cpos_y-source1[0] ) * ( cpos_y-source1[0] )
104+
+ ( cpos_x-source1[1] ) * ( cpos_x-source1[1] );
105+
if (square_dist1 <= source1[2] * source1[2]) {
95106
dat[yy][xx] = source1[3];
96107
}
97-
if((cpos_y-source2[0])*(cpos_y-source2[0]) + (cpos_x-source2[1])*(cpos_x-source2[1]) <= source2[2]*source2[2]) {
108+
square_dist2 = ( cpos_y-source2[0] ) * ( cpos_y-source2[0] )
109+
+ ( cpos_x-source2[1] ) * ( cpos_x-source2[1] );
110+
if (square_dist2 <= source2[2] * source2[2]) {
98111
dat[yy][xx] = source2[3];
99112
}
100113
}
@@ -119,7 +132,7 @@ void iter(double cur[dsize[0]][dsize[1]], double next[dsize[0]][dsize[1]])
119132
}
120133
}
121134

122-
/** Exchanges ghost values with neighbours
135+
/** Exchange ghost values with neighbours
123136
* \param[in] cart_comm the MPI communicator with all processes organized in a 2D Cartesian grid
124137
* \param[in] cur the local data at the current time-step whose ghosts need exchanging
125138
*/
@@ -146,8 +159,8 @@ void exchange(MPI_Comm cart_comm, double cur[dsize[0]][dsize[1]])
146159

147160
// send up
148161
MPI_Cart_shift(cart_comm, 0, -1, &rank_source, &rank_dest);
149-
MPI_Sendrecv(&cur[1][1], 1, row, rank_dest, 100, // send column after ghost
150-
&cur[dsize[0]-1][1], 1, row, rank_source, 100, // receive last column (ghost)
162+
MPI_Sendrecv(&cur[1][1], 1, row, rank_dest, 100, // send row after ghost
163+
&cur[dsize[0]-1][1], 1, row, rank_source, 100, // receive last row (ghost)
151164
cart_comm, &status);
152165

153166
// send to the right
@@ -158,17 +171,14 @@ void exchange(MPI_Comm cart_comm, double cur[dsize[0]][dsize[1]])
158171

159172
// send to the left
160173
MPI_Cart_shift(cart_comm, 1, -1, &rank_source, &rank_dest);
161-
MPI_Sendrecv(&cur[1][1], 1, column, rank_dest, 100, // send column after ghost
174+
MPI_Sendrecv(&cur[1][1], 1, column, rank_dest, 100, // send column after ghost
162175
&cur[1][dsize[1]-1], 1, column, rank_source, 100, // receive last column (ghost)
163176
cart_comm, &status);
164177
}
165178

166179
int main( int argc, char* argv[] )
167180
{
168181
MPI_Init(&argc, &argv);
169-
srand( time( NULL ) );
170-
171-
int switch_iter_value[10] = {20, 35, 50, 55, 60, 35, 25, 20, 15, 60 };
172182

173183
// load the configuration tree
174184
PC_tree_t conf = PC_parse_path("ex12.yml");
@@ -202,7 +212,7 @@ int main( int argc, char* argv[] )
202212
assert(global_size[1]%psize[1]==0);
203213
assert(psize[1]*psize[0] == psize_1d);
204214

205-
// compute the local data-size with space for ghosts and boundary constants
215+
// compute the local data-size (the number of ghost layers is 2 for each coordinate)
206216
dsize[0] = global_size[0]/psize[0] + 2;
207217
dsize[1] = global_size[1]/psize[1] + 2;
208218

ex12.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# the alpha parameter
22
alpha: 0.125
3-
# global data-size (excluding spacer for boundary conditions or ghosts)
3+
# global data-size (excluding the number of ghost layers for boundary conditions)
44
global_size: { height: 60, width: 12 }
55
# degree of parallelism (number of blocks in each dimension)
66
parallelism: { height: 2, width: 2 }

ex2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ double source1[4]={0.4, 0.4, 0.2, 100};
5454
double source2[4]={0.7, 0.8, 0.1, 200};
5555
// the order of the coordinates of the center (XX,YY) is inverted in the vector
5656

57-
/** Initialize all the data to 0, with the exception of a given cell
57+
/** Initialize all the data to 0, with the exception of each cells
5858
* whose center (cpos_x,cpos_y) is inside of the disks
5959
* defined by source1 or source2
6060
* \param[out] dat the local data to initialize

ex3.c

+22-9
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,31 @@
3232
// load the PDI header
3333
#include <pdi.h>
3434

35-
/// size of the local data as [HEIGHT, WIDTH] including ghosts & boundary constants
35+
// size of the local data as [HEIGHT, WIDTH] including the number of ghost layers
36+
// for communications or boundary conditions
3637
int dsize[2];
3738

38-
/// 2D size of the process grid as [HEIGHT, WIDTH]
39+
// 2D size of the process grid as [HEIGHT, WIDTH]
3940
int psize[2];
4041

41-
/// 2D rank of the local process in the process grid as [YY, XX]
42+
// 2D rank of the local process in the process grid as [YY, XX]
4243
int pcoord[2];
4344

44-
/// the alpha coefficient used in the computation
45+
// the alpha coefficient used in the computation
4546
double alpha;
4647

4748
double L=1.0;
49+
// definition of the source
50+
// the source corresponds to a disk of an uniform value
51+
// source1: center=(0.4,0.4), radius=0.2 and value=100
4852
double source1[4]={0.4, 0.4, 0.2, 100};
53+
// source2: center=(0.8,0.7), radius=0.1 and value=200
4954
double source2[4]={0.7, 0.8, 0.1, 200};
55+
// the order of the coordinates of the center (XX,YY) is inverted in the vector
5056

51-
/** Initialize the data all to 0 except for the left border (XX==0) initialized to 1 million
57+
/** Initialize all the data to 0, with the exception of each cells
58+
* whose center (cpos_x,cpos_y) is inside of the disks
59+
* defined by source1 or source2
5260
* \param[out] dat the local data to initialize
5361
*/
5462
void init(double dat[dsize[0]][dsize[1]])
@@ -58,14 +66,19 @@ void init(double dat[dsize[0]][dsize[1]])
5866
double dx = L / ((dsize[1]-2) *psize[1]) ;
5967

6068
double cpos_x,cpos_y;
69+
double square_dist1, square_dist2;
6170
for(int yy=0; yy<dsize[0];++yy) {
6271
cpos_y=(yy+pcoord[0]*(dsize[0]-2))*dy-0.5*dy;
6372
for(int xx=0; xx<dsize[1];++xx) {
6473
cpos_x=(xx+pcoord[1]*(dsize[1]-2))*dx-0.5*dx;
65-
if((cpos_y-source1[0])*(cpos_y-source1[0]) + (cpos_x-source1[1])*(cpos_x-source1[1]) <= source1[2]*source1[2]) {
74+
square_dist1 = ( cpos_y-source1[0] ) * ( cpos_y-source1[0] )
75+
+ ( cpos_x-source1[1] ) * ( cpos_x-source1[1] );
76+
if (square_dist1 <= source1[2] * source1[2]) {
6677
dat[yy][xx] = source1[3];
6778
}
68-
if((cpos_y-source2[0])*(cpos_y-source2[0]) + (cpos_x-source2[1])*(cpos_x-source2[1]) <= source2[2]*source2[2]) {
79+
square_dist2 = ( cpos_y-source2[0] ) * ( cpos_y-source2[0] )
80+
+ ( cpos_x-source2[1] ) * ( cpos_x-source2[1] );
81+
if (square_dist2 <= source2[2] * source2[2]) {
6982
dat[yy][xx] = source2[3];
7083
}
7184
}
@@ -90,7 +103,7 @@ void iter(double cur[dsize[0]][dsize[1]], double next[dsize[0]][dsize[1]])
90103
}
91104
}
92105

93-
/** Exchanges ghost values with neighbours
106+
/** Exchange ghost values with neighbours
94107
* \param[in] cart_comm the MPI communicator with all processes organized in a 2D Cartesian grid
95108
* \param[in] cur the local data at the current time-step whose ghosts need exchanging
96109
*/
@@ -170,7 +183,7 @@ int main( int argc, char* argv[] )
170183
assert(global_size[1]%psize[1]==0);
171184
assert(psize[1]*psize[0] == psize_1d);
172185

173-
// compute the local data-size with space for ghosts and boundary constants
186+
// compute the local data-size (the number of ghost layers is 2 for each coordinate)
174187
dsize[0] = global_size[0]/psize[0] + 2;
175188
dsize[1] = global_size[1]/psize[1] + 2;
176189

ex3.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# the alpha parameter
22
alpha: 0.125
3-
# global data-size (excluding spacer for boundary conditions or ghosts)
3+
# global data-size (excluding the number of ghost layers for boundary conditions)
44
global_size: { height: 60, width: 12 }
55
# degree of parallelism (number of blocks in each dimension)
66
parallelism: { height: 1, width: 1 }

0 commit comments

Comments
 (0)