-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMCSH_test.c
307 lines (220 loc) · 8.59 KB
/
MCSH_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
#include <assert.h>
#include <mpi.h>
# include <math.h>
/* BLAS, LAPACK, LAPACKE routines */
#ifdef USE_MKL
// #define MKL_Complex16 double complex
#include <mkl.h>
#else
#include <cblas.h>
#endif
#include "MCSHHelper.h"
#include "MCSH.h"
#include "MCSHDescriptorMain.h"
#include "test_data.h"
int main(int argc, char *argv[])
{
MPI_Init(&argc,&argv);
int world_rank, world_size;
double start = MPI_Wtime();
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int numProcPerRow = 1;
int color = world_rank / numProcPerRow; // Determine color based on row
// Split the communicator based on the color and use the
// original rank for ordering
MPI_Comm row_comm;
MPI_Comm_split(MPI_COMM_WORLD, color, world_rank, &row_comm);
int numParallelComm = world_size / numProcPerRow;
int imageDimX = 26, imageDimY = 26, imageDimZ = 26;
// double *rho = malloc( imageDimX * imageDimY * imageDimZ * sizeof(double));
double *rho = Pt_test;
int ii, imageSize = imageDimX * imageDimY * imageDimZ;
double current = 0.0;
for (ii = 0; ii < imageSize; ii++)
{
rho[ii] = current;
current += 1.0;
}
double hx = 0.1, hy = 0.1, hz = 0.1;
double Uvec[9] = {0.0, 0.707106781186548, 0.707106781186548, 0.707106781186548, 0.0, 0.707106781186548, 0.707106781186548, 0.707106781186548, 0.0};
double *U = Uvec;
int accuracy = 2;
int MCSHMaxOrder = 3;
double MCSHMaxR = 0.6;
double MCSHRStepsize = 0.1;
// printf("\nstart MCSH\n");
// MCSHDescriptorMain_RadialRStep(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, U, accuracy, MCSHMaxOrder, MCSHMaxR, MCSHRStepsize, color, numParallelComm, row_comm);
MCSHDescriptorMain_RadialLegendre(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, U, accuracy, 0.5, MCSHMaxOrder, 5, color, numParallelComm, row_comm);
double end = MPI_Wtime();
printf("\n\n END execution time %10f\n\n", end - start);
MPI_Finalize();
// printf("after MPI finalize\n");
return 0;
}
int main_old(int argc, char *argv[])
{
MPI_Init(&argc,&argv);
int world_rank, world_size;
double start = MPI_Wtime();
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int numProcPerRow = 1;
int color = world_rank / numProcPerRow; // Determine color based on row
// Split the communicator based on the color and use the
// original rank for ordering
MPI_Comm row_comm;
MPI_Comm_split(MPI_COMM_WORLD, color, world_rank, &row_comm);
int numParallelComm = world_size / numProcPerRow;
int imageDimX = 60, imageDimY = 60, imageDimZ = 60;
double *rho = malloc( imageDimX * imageDimY * imageDimZ * sizeof(double));
int ii, imageSize = imageDimX * imageDimY * imageDimZ;
double current = 0.0;
for (ii = 0; ii < imageSize; ii++)
{
rho[ii] = current;
current += 1.0;
}
double hx = 0.1, hy = 0.1, hz = 0.1;
double Uvec[9] = {1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0};
double *U = Uvec;
int accuracy = 6;
int MCSHMaxOrder = 3;
double MCSHMaxR = 0.6;
double MCSHRStepsize = 0.1;
// printf("\nstart MCSH\n");
// MCSHDescriptorMain_RadialRStep(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, U, accuracy, MCSHMaxOrder, MCSHMaxR, MCSHRStepsize, color, numParallelComm, row_comm);
MCSHDescriptorMain_RadialLegendre(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, U, accuracy, 0.5, MCSHMaxOrder, 5, color, numParallelComm, row_comm);
double end = MPI_Wtime();
printf("\n\n END execution time %10f\n\n", end - start);
MPI_Finalize();
// printf("after MPI finalize\n");
return 0;
}
int main_set(int argc, char *argv[])
{
MPI_Init(&argc,&argv);
int world_rank, world_size;
double start = MPI_Wtime();
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int numProcPerRow = 1;
int color = world_rank / numProcPerRow; // Determine color based on row
// Split the communicator based on the color and use the
// original rank for ordering
MPI_Comm row_comm;
MPI_Comm_split(MPI_COMM_WORLD, color, world_rank, &row_comm);
int numParallelComm = world_size / numProcPerRow;
int imageDimX = 60, imageDimY = 60, imageDimZ = 60;
double *rho = malloc( imageDimX * imageDimY * imageDimZ * sizeof(double));
int ii, imageSize = imageDimX * imageDimY * imageDimZ;
double current = 0.0;
for (ii = 0; ii < imageSize; ii++)
{
rho[ii] = current;
current += 1.0;
}
double hx = 0.1, hy = 0.1, hz = 0.1;
double Uvec[9] = {1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0};
double *U = Uvec;
int accuracy = 6;
MCSHDescriptorMainFixed_RadialRStep(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, U, accuracy, color, numParallelComm, row_comm);
double end = MPI_Wtime();
printf("\n\n END execution time %10f\n\n", end - start);
MPI_Finalize();
// printf("after MPI finalize\n");
return 0;
}
int main_single(int argc, char *argv[])
{
/*printf("start\n");
double Uvec[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
double *U = Uvec;
calcStencil(0.1, 0.1, 0.1, 0.5, 1, "100", U, 6, 0);*/
MPI_Init(&argc,&argv);
int rank, numProc;
MPI_Comm_size(MPI_COMM_WORLD, &numProc);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("rank %d out of %d\n", rank, numProc);
int imageDimX = 100, imageDimY = 100, imageDimZ = 100;
double *rho = malloc( imageDimX * imageDimY * imageDimZ * sizeof(double));
int ii, imageSize = imageDimX * imageDimY * imageDimZ;
double current = 0.0;
for (ii = 0; ii < imageSize; ii++)
{
rho[ii] = current;
current += 1.0;
}
double hx = 0.1, hy = 0.1, hz = 0.1;
// double Uvec[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
// double Uvec[9] = {1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0};
double Uvec[9] = {1.0, -0.292371704722737, 0.17364817766693, 0.0, 0.956304755963035, -0.110492654830881, 0.0, 0.0, 0.978589640054184};
double *U = Uvec;
double normalizedU[9];
normalizeU(U, normalizedU);
int accuracy = 6;
printf("\n hx: %f \t hy: %f \t hz: %f \nU: \n %f \t %f \t %f \n %f \t %f \t %f \n %f \t %f \t %f \n",
hx, hy, hz, normalizedU[0], normalizedU[3], normalizedU[6], normalizedU[1], normalizedU[4], normalizedU[7], normalizedU[2], normalizedU[5], normalizedU[8] );
// int length = 10;
// double rCutoffList[10] = {0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5};
// int lList[10] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
// char *nList[] = {"000", "100", "000", "100", "000", "100", "000", "100", "000", "100"};
// int length = 7;
// double rCutoffList[7] = {0.5, 0.5, 0.5, 0.5,0.5,0.5,0.5};
// int lList[7] = {0, 1,2,2,3,3,3};
// int groupList[7] = {1,1,1,2,1,2,3};
int length = 2;
double rCutoffList[2] = {0.5, 0.5};
int lList[2] = {0, 1};
char *nList[] = {"000", "100"};
int groupList[2] = {1,1};
// char **nListPointer = nList;
int i;
int rankCount;
double *featureVector = malloc( imageSize * sizeof(double));
for ( i = 0; i < imageSize; i++)
{
featureVector[i] = 0.0;
}
for (i = 0; i < length; i++){
if (rank == i % numProc){
printf("rank %d, index %d\n", rank, i);
//calcStencil(const double hx, const double hx, const double hz, const double rCutoff, const int l, const char *n, const double *U, const int accuracy);
// calcStencilAndSave(hx, hy, hz, rCutoffList[i], lList[i], nList[i], U, accuracy,i);
// calcStencilAndConvolveAndSave(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, rCutoffList[i], lList[i], nList[i], U, accuracy,i);
prepareMCSHFeatureAndSave(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, rCutoffList[i], lList[i], groupList[i], 1, 0, normalizedU, accuracy);
// calcStencilAndConvolveAndAddResult(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, rCutoffList[i], lList[i], nList[i], normalizedU, accuracy, featureVector);
}
}
MPI_Finalize();
return 0;
}
// int main(int argc, char *argv[])
// {
// int imageDimX = 100, imageDimY = 100, imageDimZ = 100;
// double *rho = malloc( imageDimX * imageDimY * imageDimZ * sizeof(double));
// int ii, imageSize = imageDimX * imageDimY * imageDimZ;
// double current = 0.0;
// for (ii = 0; ii < imageSize; ii++)
// {
// rho[ii] = current;
// current += 1.0;
// }
// double hx = 0.1, hy = 0.1, hz = 0.1;
// double Uvec[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
// double *U = Uvec;
// int accuracy = 6;
// int length = 10;
// double rCutoffList[10] = {0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5};
// int lList[10] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
// char *nList[] = {"000", "100", "000", "100", "000", "100", "000", "100", "000", "100"};
// // char **nListPointer = nList;
// int i;
// int rankCount;
// for (i = 0; i < length; i++){
// calcStencilAndConvolve(rho, imageDimX, imageDimY, imageDimZ, hx, hy, hz, rCutoffList[i], lList[i], nList[i], U, accuracy,i);
// }
// }