-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_powermethod.c
More file actions
687 lines (595 loc) · 21.2 KB
/
test_powermethod.c
File metadata and controls
687 lines (595 loc) · 21.2 KB
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
// HT requirements
#define _GNU_SOURCE
#include <string.h> // for memcmp
#include <assert.h>
#include <stdlib.h> // for free for _SC_NPROCESSORS_ONLN for gethostname
#include <math.h> // for pow, round
#include <algorithms.h>
#include <gen_utils.h> // for reset_array_sizet
#include <gen_data.h> // get_vector, gen_vector, gen_block_tensor
#include <file_utils.h> // for save_to_file
#include <unistd.h> //
#include <bench_utils.h>
#include <time_meas.h>
// test case: add some code which appears only in tests
// test case: make numbers round (or integers!)
// These are all numbers of doubles
#define L1 4096.0 // 32 KB
#define L1_measured 2048.0
#define L3 3276800.0
#define L3_measured 2097152.0 // 16 MB of L3 taken for the measurement (not half...)
#define RAM_new 5368709120.0
#define RAM 4294967296.0 // not the actual max of RAM, just 32 GB (double RAM_measured)
#define RAM_measured 2684354560.0 // 20 GB
#define BENCH_SIZE_RESULT 9 // size_10d = 9 is 3GB
#define MINI_BENCH_SIZE 10077696.0 // RAM_measured/4
#define MINI_BENCH_SIZE_RESULT 5 // size_10d = 8 is 1GB
#define TENGIGABYTES 1342177280
#define TENGIGABYTES_RESULT 8
#define FIXFORSEVEND 1801088541
// #define SINGLEBLOCK
#define ONEBLOCKSIZE
#define BLOCK_SIZES 3
// For now, normalize input tensor only for the test case (stochastic tensor)
#if (TEST_ENV == 1) || defined(SINGLEBLOCK)
#define SIZE 10077696.0
// #define NORMALIZE
#else
#define SIZE TENGIGABYTES // MINI_BENCH_SIZE
#endif
#define FILENAME(x); snprintf(filename, BUFSIZE, "%s/%s_%.0f_dimmin_%d_dimmax_%d_nmin_%d_nmax_%d_modemin_%d_modemax_%d_blockn_%d_%s.csv", FOLDER, hostname, timespec_to_microseconds(time), dim_min, dim_max, 0, 0, 0, 0, 0, x)
#define epsilon 1e-3 // adjusted from 1e-6 to 1e-5
inline int fequal(double a, double b) {
return fabs(a-b) < epsilon;
}
extern int compare( const void* _a, const void* _b);
#ifndef bitmask_t_
#define bitmask_t_
#define bitmask_t unsigned long long
#endif
int
lin_compare(const struct lin_storage * const model, const struct lin_storage * const trial) {
size_t pos = 0;
while ( fequal(model->data[pos], trial->data[pos]) ) {
if (++pos == model->size) {
break;
}
}
if (pos != model->size) {
printf("error: compare %lf vs %lf (eror is %lf)\n", model->data[pos-1], trial->data[pos-1], fabs(model->data[pos-1]-trial->data[pos-1]));
printf("from where its broken till end:\n");
size_t print_size = model->size - pos;
if (print_size > 20) {
print_size = 20;
}
print_to_console(model->data + pos, print_size);
print_to_console(trial->data + pos, print_size);
exit(-1);
// printf("this particular vector is not equal\n");
return 0;
} else {
// printf("this particular vector is equal\n");
return 1;
}
}
int
lin_compare_series(struct lin_storage ** const model_array, struct lin_storage ** const compare_array, int array_size) {
int equal = 1;
size_t edge_size = compare_array[0]->size;
for (int i=0; i<array_size; ++i) {
// Compare each lin_storage in the array
int subequal = lin_compare(model_array[i], compare_array[i]);
// printf("comparing: with:\n");
// print_to_console(model_array[i]->data, array_size);
// print_to_console(compare_array[i]->data, array_size);
equal &= subequal;
if (equal != 1) {
printf("error found in vector %d\n", i);
}
}
if (equal == 1) {
printf("lin_compare_series: arrays are equal\n");
} else {
size_t print_size = edge_size;
if (print_size > 10) {
print_size = 10;
}
printf("lin_compare_series: error found in one of the vectors\n");
for (int d=0; d<array_size; ++d) {
printf("%d: ", d);
print_to_console(compare_array[d]->data, print_size);
}
exit(-1);
}
return equal;
}
int test_powermethod(int argc, char ** argv) {
int algo_to_test;
if (TEST_ENV == 1) {
algo_to_test = 4; // count pmModel in
} else {
algo_to_test = 4; // count pmModel in
}
TVM algorithms_powermethod[] = {
pmModel,
pmMortonLibx,
pmBlockLibx,
pmLooped,
pmMorton,
pmBlock,
// pmTaco10, // works only for 10D(!)
// pmTaco5,
pmMortonLibxVms,
pmMortonLibxSingle,
pmMortonLibxSingleMvs,
pmMortonSingleMvs,
pmLoopedSingle,
pmBlockSingleMvs,
pmLoopedSingleMvs,
pmMortonSingle,
pmMortonMyself,
};
int dim_min = 2;
int dim_max = 2;
switch (argc) {
case 2:
sscanf (*(argv+argc--), "%d", &dim_max);
sscanf (*(argv+argc--), "%d", &dim_min);
}
char hostname[1024];
gethostname(hostname, 1024);
struct timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
char filename[BUFSIZE];
if (TEST_ENV == 1) {
printf("test_powermethod.c: TEST ENV\n");
FILENAME("test");
} else {
printf("test_powermethod.c: REAL ENV\n");
FILENAME("bench");
}
printf("filename=%s\n", filename);
// printf("BUFSIZE is %d, FOLDER is %s, TIME is %.0f\n", BUFSIZE, FOLDER, timespec_to_microseconds(time));
FILE * file;
if (TEST_ENV == 0) {
file = fopen(filename, "w"); // r+ if you want to update without deleteing it
if (file == NULL) {
perror("Error opening file.\n");
}
write_powermethod_header(file);
}
size_t size_1d, size_10d;
size_1d = SIZE;
if (TEST_ENV == 1) {
printf("We are in test environment.");
size_10d = ceil(pow(size_1d, 1/(double)10));
} else {
size_10d = TENGIGABYTES_RESULT; // BENCH_SIZE_RESULT;
}
#ifdef SINGLEBLOCK
size_10d = ceil(pow(size_1d, 1/(double)10));
#endif
printf("size_1d = %zu, size_10d = %zu\n", size_1d, size_10d);
struct tensor_storage * const tensor = gen_block_tensor_clean(1, &size_1d, &size_1d);
printf("10 el of tensor memory: ");
print_to_console(tensor->lin.data, 10);
// block_layout (init stage, same as layout)
free(tensor->block_layout);
tensor->block_layout = copy_array_int(tensor->layout, tensor->dim);
print_to_console_sizet(tensor->block_layout, tensor->dim);
// Vector size is at most half of size_1d
size_t size_max_vector = ceil(pow(size_1d, 1.0/(double)2));
printf("Size of each vector is half of the total linear size (worst case): %zu\n", size_max_vector);
struct lin_storage * vector_array[dim_max];
struct lin_storage * number_vectors[dim_max];
struct lin_storage * model_vector[dim_max];
for (int i=0; i<dim_max; ++i) {
vector_array[i] = gen_vector_seeded(size_max_vector, i);
number_vectors[i] = gen_vector_seeded(size_max_vector, i);
}
if (TEST_ENV == 1) {
for (int i=0; i<dim_max; ++i) {
model_vector[i] = gen_vector_seeded(size_max_vector, i);
}
}
// Precalculate how much memory is needed for the result -> for now assume the worst case, which is 10D
// size per dimension for dim_max case
size_t size_maxd_result = ceil(pow(size_1d, 1/(double)dim_max));
size_t size_max_result = pow(size_maxd_result, dim_max-1);
if (size_max_result > size_1d) {
printf("Should never happen?, size_max_result points to %zu", size_max_result);
size_max_result = size_1d;
}
printf("Size of temp result is in total (worst case): %zu\n", size_max_result);
printf("Allocating result tensors:\n");
struct tensor_storage * const result_1 = gen_block_tensor_clean(1, &size_max_result, &size_max_result);
struct tensor_storage * const result_2 = gen_block_tensor_clean(1, &size_max_result, &size_max_result);
for (size_t dim=(size_t) dim_min; dim<=(size_t) dim_max; ++dim) {
printf("\ndim = %zu ==================================================================\n", dim);
size_t block_array[BLOCK_SIZES];
size_t size_1d_modified = floor(pow(size_1d, 1/(double)dim));
printf("(dim %zu) n (calculated): %zu\n", dim, size_1d_modified);
// if (TEST_ENV == 1) {
// assert(pow(size_1d_modified, dim) <= (double) size_1d);
// size_t block_dim_length = floor(pow(size_1d, 1/(double)dim));
// if (block_dim_length > size_1d_modified) {
// printf("reduce block size; ");
// block_dim_length = size_1d_modified;
// }
// if (size_1d_modified % block_dim_length != 0) {
// printf("make it divisible; ");
// block_dim_length = size_1d_modified;
// }
// printf("(dim %zu) block_n (calculated): %zu\n", dim, block_dim_length);
// // Currently in test case we assume block size (2)
// // Let's change it to have more than 1 block size ?
// block_array[0] = 2;
// block_array[1] = 3;
// block_array[2] = 0;
// block_array[0] = 2;
// block_array[1] = 2;
if (dim == 2) {
block_array[0] = 44;
block_array[1] = 124;
block_array[2] = 1276; // 10% (2.6MB): 572; 13MB: 1276;
} else if (dim == 3) {
block_array[0] = 12;
block_array[1] = 24;
block_array[2] = 116; // 10% (2.5MB): 68; 12.5MB: 116;
} else if (dim == 4) {
block_array[0] = 6;
block_array[1] = 10;
block_array[2] = 34; // 10% (2.7MB): 24; 10MB: 34;
} else if (dim == 5) {
block_array[0] = 4;
block_array[1] = 6;
block_array[2] = 16; // 10% (2MB): 12; 8.5MB: 16;
} else if (dim == 6) {
block_array[0] = 3;
block_array[1] = 4;
block_array[2] = 10; // 10% (2MB): 8; 8MB: 10;
} else if (dim == 7) {
block_array[0] = 2;
block_array[1] = 4;
block_array[2] = 9;//8;//7; // 10% (2.2MB): 6; 6.6MB: 7;
} else if (dim == 8) {
block_array[0] = 2;
block_array[1] = 3;
block_array[2] = 6;//5; // 10% (3MB): 5;
} else if (dim == 9) {
block_array[0] = 2;
block_array[1] = 3;
block_array[2] = 5;//4; // 10% (2MB): 4; 15MB: 5;
} else if (dim == 10) {
block_array[0] = 2;
block_array[1] = 4; // ?% (8MB): 4;
block_array[2] = 0;
}
printf("(dim %zu) block_n (final): ", dim);
print_to_console_sizet(block_array, BLOCK_SIZES);
// CRUCIAL (!!!) OTHERWISE BUGS
tensor->dim = dim;
result_1->dim = dim - 1;
result_2->dim = dim - 1;
// reset_array_sizet(tensor_layout, dim, size_1d_modified);
// printf(" n = ");
// print_to_console_sizet(tensor_layout, dim);
// free(tensor->layout);
// free(tensor->layout_perm);
// set_tensor_layout(tensor, tensor_layout);
// // technically it's enoguh to just do this
// free(result_1->layout);
// free(result_1->layout_perm);
// set_tensor_layout(result_1, tensor_layout);
// free(result_2->layout);
// free(result_2->layout_perm);
// set_tensor_layout(result_2, tensor_layout);
// for (int i=0; i<dim; ++i) {
// vector_array[i]->size = size_1d_modified;
// model_vector[i]->size = size_1d_modified;
// }
// // if (TEST_ENV == 1) {
// // round_numbers(tensor->lin.data, tensor->lin.size);
// for (int i=0; i<dim; ++i) {
// double size1 = normalize(vector_array[i], size_1d_modified);
// double size2 = normalize(model_vector[i], size_1d_modified);
// }
// // }
// lin_compare_series(model_vector, vector_array, dim);
// Here we already know the dimensionality, etc
// Normalize per row
#ifdef NORMALIZE
normalize_rows(tensor, 0);
#endif
// printf("Initial vectors (normalized as vectors of %zu elements i.e. mode size):\n", size_1d_modified);
// for (int d=0; d<dim; ++d) {
// printf("%d: ", d);
// print_to_console(vector_array[d]->data, 4);
// }
/////////////////////////////////////////////////////// SETUP
// ALl those algorithms rely on the following:
// Size of: tensor, vector, result
// Additionally: tensor layout and dim
///////////////////////////////////////////////////////
#define ITERATIONS 1
///////////////////////////////////////////////////////
// printf("\nMODEL ALGORITHM\n");
// struct tensor_storage * input;
// struct lin_storage * output;
// for (int iter=0; iter<ITERATIONS; ++iter) {
// for (int vector_up=0; vector_up<dim; ++vector_up) {
// #ifdef DEBUG_ENV
// printf("vector_up=%d, \n", vector_up);
// #endif
// // in/out set for iterations == 0(!)
// int iterations = 0;
// input = tensor;
// output = &result_1->lin;
// for (int mode=dim-1; mode>=0; --mode) {
// if (mode == vector_up) continue;
// #ifdef DEBUG_ENV
// printf("compute with mode %d\n", mode);
// #endif
// if (iterations == dim-2) {
// // printf("Output is a vector!\n");
// output = model_vector[vector_up];
// }
// input->dim = dim-iterations;
// output->size = input->lin.size / model_vector[0]->size;
// // printf("input: %zu (dim %zu), output: %zu\n",
// // input->lin.size, input->dim,
// // output->size);
// tvm_vector_major_BLAS_col_mode(input, model_vector[mode], output, mode);
// // printf("Current state\n");
// // print_to_console(output->data, output->size);
// ++iterations;
// if (iterations % 2 == 0) {
// output = &result_1->lin;
// reset_array(result_1->lin.data, result_1->lin.size, 0);
// input = result_2;
// } else {
// output = &result_2->lin;
// reset_array(result_2->lin.data, result_2->lin.size, 0);
// input = result_1;
// }
// }
// #ifdef NORMALIZE
// // printf("norm, ");
// (void) normalize(model_vector[vector_up], size_1d_modified);
// #endif
// }
// // printf("\n");
// }
// result_1->dim = dim;
// result_2->dim = dim;
// if (TEST_ENV == 1) {
// // Printing one of the model vectors
// printf("Model vectors (normalized):\n");
// for (int d=0; d<dim; ++d) {
// printf("%d: ", d);
// print_to_console(model_vector[d]->data, size_1d_modified);
// }
// printf("\n");
// }
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
for (size_t block_id=0; block_id<BLOCK_SIZES; block_id++) {
size_t block_dim_length = block_array[2];
if (block_dim_length == 0) {
block_dim_length = block_array[1];
// break;
}
printf("\nblock_n = %zu ======================================\n", block_dim_length);
// Technically this code for the benchmarking case can be simplified (!) we do not need an actual blocked tensor...
size_t block_layout[dim];
reset_array_sizet(block_layout, dim, block_dim_length);
printf("block_n = ");
print_to_console_sizet(block_layout, dim);
free(tensor->block_layout);
tensor->block_layout = copy_array_int(block_layout, dim);
size_t result_block_layout[dim];
reset_array_sizet(result_block_layout, dim-1, block_dim_length);
free(result_1->block_layout);
free(result_2->block_layout);
result_1->block_layout = copy_array_int(result_block_layout, dim-1);
result_2->block_layout = copy_array_int(result_block_layout, dim-1);
// Make the tensor divisible
#ifdef SINGLEBLOCK
size_t temp = 1;
#else
size_t temp = size_1d_modified/block_dim_length;
if (temp == 0) {
temp = 1;
}
while (temp>1 && pow(temp*block_dim_length,dim)>size_1d) {
temp--;
printf("decreasing the temp size to match available tensor memory; ");
}
#endif
printf("Number of block in each dimension is %zu. Taking in total %zu elements in each dimension. That raised to the dimensionality of the tensor is pow(%zu, %zu) = %d. Total available size is %zu.\n",
temp,
temp*block_dim_length,
temp*block_dim_length,
dim,
(int) pow(temp*block_dim_length,dim),
size_1d);
assert(pow(temp*block_dim_length,dim)<=size_1d);
size_t size_1d_local = temp*block_dim_length;
printf("n: %zu (ensures divisibility)\n", size_1d_local);
size_t tensor_layout[dim];
reset_array_sizet(tensor_layout, dim, size_1d_local);
free(tensor->layout);
free(tensor->layout_perm);
set_tensor_layout(tensor, tensor_layout);
size_t result_tensor_layout[dim];
reset_array_sizet(result_tensor_layout, dim-1, size_1d_local);
free(result_1->layout);
free(result_1->layout_perm);
free(result_2->layout);
free(result_2->layout_perm);
set_tensor_layout(result_1, result_tensor_layout);
set_tensor_layout(result_2, result_tensor_layout);
// CAREFUL (!!!!) MODIFY THIS
struct tensor_storage *blocked_tensor;
struct tensor_storage *morton_blocked_tensor;
if (TEST_ENV == 1) {
printf("Allocating blocked (and morton blocked) tensors for correctness (REMOVE FROM BENCHMARKING)\n");
blocked_tensor = get_block_tensor(tensor, 0, 0);
morton_blocked_tensor = get_block_tensor(tensor, 0, 1);
}
for (int algo_id=0; algo_id<algo_to_test; ++algo_id) {
printf("\n");
// Skip the model algorithm if we are not testing
if (TEST_ENV == 0 && algo_id == 0) {
printf("Do not benchmark the model algorithm\n");
continue;
}
// Execute pmLooped only once
// if (block_id !=0 && (
// algorithms_powermethod[algo_id] == pmLooped ||
// algorithms_powermethod[algo_id] == pmLoopedSingle ||
// algorithms_powermethod[algo_id] == pmLoopedSingleMvs)) {
// continue;
// }
// If benchmarking, do not need to reset the vectors? -> I think we do(?)
// double check if this is not done in bench utils
// If testing, reset like the following but if benchmarking we never reset (or need) the model vectors
if (TEST_ENV == 1) {
for (size_t j=0; j<dim; ++j) {
vector_array[j]->size = size_1d_local;
model_vector[j]->size = size_1d_local;
if (algo_id == 0) {
for (size_t el=0; el<size_1d_local; ++el) {
model_vector[j]->data[el] = number_vectors[j]->data[el];
}
} else {
for (size_t el=0; el<size_1d_local; ++el) {
vector_array[j]->data[el] = number_vectors[j]->data[el];
}
}
}
size_t print_size = size_1d_local;
if (print_size > 10) {
print_size = 10;
}
// printf("Vectors (at most 10 el):\n");
// for (size_t i=0; i<dim; ++i) {
// printf("%zu: ", i);
// print_to_console(vector_array[i]->data, print_size);
// }
}
// Set which tensor will be used as input
struct tensor_storage * input_tensor = tensor;
if (TEST_ENV == 1) {
if (algorithms_powermethod[algo_id] == pmMorton ||
algorithms_powermethod[algo_id] == pmMortonMyself ||
algorithms_powermethod[algo_id] == pmMortonLibx ||
algorithms_powermethod[algo_id] == pmMortonLibxVms ||
algorithms_powermethod[algo_id] == pmMortonSingle ||
algorithms_powermethod[algo_id] == pmMortonLibxSingle ||
algorithms_powermethod[algo_id] == pmMortonSingleMvs ||
algorithms_powermethod[algo_id] == pmMortonLibxSingleMvs) {
printf("Selecting morton blocked tensor as input.\n");
input_tensor = morton_blocked_tensor;
} else if (algorithms_powermethod[algo_id] == pmLooped ||
algorithms_powermethod[algo_id] == pmTaco10 ||
algorithms_powermethod[algo_id] == pmTaco5 ||
algorithms_powermethod[algo_id] == pmLoopedSingle ||
algorithms_powermethod[algo_id] == pmLoopedSingleMvs ||
algorithms_powermethod[algo_id] == pmModel) {
printf("Selecting regular tensor as input.\n");
input_tensor = tensor;
} else {
printf("Selecting blocked tensor as input.\n");
input_tensor = blocked_tensor;
}
}
if (TEST_ENV == 1) {
printf("Algorithm %d; Resetting the result_1 and result_2\n", algo_id);
reset_array(result_1->lin.data, result_1->lin.size, 0.0);
reset_array(result_2->lin.data, result_2->lin.size, 0.0);
} else {
printf("Algorithm %d; Benchmark will reset the results\n", algo_id);
}
size_t print_size = size_1d_local;
if (print_size > 10) {
print_size = 10;
}
if (TEST_ENV == 1) {
if (algo_id == 0) {
algorithms_powermethod[algo_id](input_tensor, model_vector, result_1, result_2, ITERATIONS);
// Reset back those (avoids side effects)
tensor->dim = dim;
result_1->dim = dim - 1;
result_2->dim = dim - 1;
} else {
algorithms_powermethod[algo_id](input_tensor, vector_array, &result_1->lin, &result_2->lin, ITERATIONS);
for (size_t i=0; i<dim; ++i) {
printf("%zu: ", i);
print_to_console(vector_array[i]->data, print_size);
}
}
} else {
measure_powermethod(
algorithms_powermethod[algo_id],
input_tensor,
vector_array,
number_vectors, // The original vectors should be number vectors
&result_1->lin, &result_2->lin,
ITERATIONS,
file, tensor->layout[0], block_dim_length, 0);
fflush(file);
}
if (TEST_ENV == 1) {
if (algo_id == 0) {
// printf("(normalized) model_vector vectors (size_1d_local = %zu, %d iterations):\n", ITERATIONS);
for (size_t i=0; i<dim; ++i) {
// double size = normalize(model_vector[i], size_1d_local);
printf("%zu: ", i);
print_to_console(model_vector[i]->data, print_size);
}
} else {
// printf("(normalized) vector_array vectors (size_1d_local = %zu, %d iterations):\n", ITERATIONS);
for (size_t i=0; i<dim; ++i) {
// double size = normalize(vector_array[i], size_1d_local);
printf("%zu: ", i);
print_to_console(vector_array[i]->data, print_size);
}
printf("Verification result: ");
lin_compare_series(model_vector, vector_array, dim);
}
} else {
printf("Vectors (at most 10 el):\n");
for (size_t i=0; i<dim; ++i) {
printf("%zu: ", i);
print_to_console(vector_array[i]->data, print_size);
}
}
}
if (TEST_ENV == 1) {
free_tensor_storage(blocked_tensor);
free_tensor_storage(morton_blocked_tensor);
}
// In case we only have one block_n to measure (!)
#ifdef ONEBLOCKSIZE
break;
#endif
}
}
free_tensor_storage(tensor);
free_tensor_storage(result_1);
free_tensor_storage(result_2);
for (int i=0; i<dim_max; ++i) {
if (TEST_ENV == 1) {
free_lin_storage(model_vector[i]);
}
free_lin_storage(vector_array[i]);
free_lin_storage(number_vectors[i]);
}
if (TEST_ENV == 0) {
if (file != NULL) {
fclose(file);
}
}
return 0;
}