-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathtstHalo.hpp
616 lines (545 loc) · 22.2 KB
/
tstHalo.hpp
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
/****************************************************************************
* Copyright (c) 2018-2023 by the Cabana authors *
* All rights reserved. *
* *
* This file is part of the Cabana library. Cabana is distributed under a *
* BSD 3-clause license. For the licensing terms see the LICENSE file in *
* the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/
#include <Cabana_AoSoA.hpp>
#include <Cabana_DeepCopy.hpp>
#include <Cabana_Halo.hpp>
#include <Cabana_Parallel.hpp>
#include <Kokkos_Core.hpp>
#include <gtest/gtest.h>
#include <mpi.h>
#include <memory>
#include <vector>
namespace Test
{
struct UniqueTestTag
{
int num_local;
int num_send;
int num_recv;
UniqueTestTag()
{
int my_size = -1;
MPI_Comm_size( MPI_COMM_WORLD, &my_size );
num_local = 2 * my_size;
num_send = my_size;
num_recv = my_size;
}
};
struct AllTestTag
{
int num_local = 1;
int num_send;
int num_recv;
AllTestTag()
{
int my_size = -1;
MPI_Comm_size( MPI_COMM_WORLD, &my_size );
num_send = my_size;
num_recv = my_size;
}
};
struct HaloData
{
// Create an AoSoA of local data with space allocated for local data.
using DataTypes = Cabana::MemberTypes<int, double[2]>;
using AoSoA_t = Cabana::AoSoA<DataTypes, TEST_MEMSPACE>;
using AoSoA_Host_t = Cabana::AoSoA<DataTypes, Kokkos::HostSpace>;
AoSoA_t aosoa;
HaloData( Cabana::Halo<TEST_MEMSPACE> halo )
{
aosoa = AoSoA_t( "data", halo.numLocal() + halo.numGhost() );
}
AoSoA_t createData( const int my_rank, const int num_local )
{
auto slice_int = Cabana::slice<0>( aosoa );
auto slice_dbl = Cabana::slice<1>( aosoa );
// Fill the local data.
auto fill_func = KOKKOS_LAMBDA( const int i )
{
slice_int( i ) = my_rank + 1;
slice_dbl( i, 0 ) = my_rank + 1;
slice_dbl( i, 1 ) = my_rank + 1.5;
};
Kokkos::RangePolicy<TEST_EXECSPACE> range_policy( 0, num_local );
Kokkos::parallel_for( range_policy, fill_func );
Kokkos::fence();
return aosoa;
}
AoSoA_Host_t copyToHost()
{
// Deep copy to check after gather/scatter.
AoSoA_Host_t aosoa_host( "data_host", aosoa.size() );
Cabana::deep_copy( aosoa_host, aosoa );
return aosoa_host;
}
};
auto createHalo( UniqueTestTag, const int use_topology, const int my_size,
const int num_local )
{
std::shared_ptr<Cabana::Halo<TEST_MEMSPACE>> halo;
// Every rank will send ghosts to all other ranks. Send one element to
// each rank including yourself. Interleave the sends. The resulting
// communication plan has ghosts that have one unique destination.
Kokkos::View<int*, Kokkos::HostSpace> export_ranks_host( "export_ranks",
my_size );
Kokkos::View<std::size_t*, Kokkos::HostSpace> export_ids_host( "export_ids",
my_size );
std::vector<int> neighbors( my_size );
for ( int n = 0; n < my_size; ++n )
{
neighbors[n] = n;
export_ranks_host( n ) = n;
export_ids_host( n ) = 2 * n + 1;
}
auto export_ranks = Kokkos::create_mirror_view_and_copy(
TEST_MEMSPACE(), export_ranks_host );
auto export_ids =
Kokkos::create_mirror_view_and_copy( TEST_MEMSPACE(), export_ids_host );
// Create the plan.
if ( use_topology )
halo = std::make_shared<Cabana::Halo<TEST_MEMSPACE>>(
MPI_COMM_WORLD, num_local, export_ids, export_ranks, neighbors );
else
halo = std::make_shared<Cabana::Halo<TEST_MEMSPACE>>(
MPI_COMM_WORLD, num_local, export_ids, export_ranks );
return halo;
}
auto createHalo( AllTestTag, const int use_topology, const int my_size,
const int num_local )
{
std::shared_ptr<Cabana::Halo<TEST_MEMSPACE>> halo;
// Every rank will send its single data point as ghosts to all other
// ranks. This will create collisions in the scatter as every rank will
// have data for this rank in the summation.
Kokkos::View<int*, Kokkos::HostSpace> export_ranks_host( "export_ranks",
my_size );
Kokkos::View<std::size_t*, TEST_MEMSPACE> export_ids( "export_ids",
my_size );
Kokkos::deep_copy( export_ids, 0 );
std::vector<int> neighbors( my_size );
for ( int n = 0; n < my_size; ++n )
{
neighbors[n] = n;
export_ranks_host( n ) = n;
}
auto export_ranks = Kokkos::create_mirror_view_and_copy(
TEST_MEMSPACE(), export_ranks_host );
// Create the plan.
if ( use_topology )
halo = std::make_shared<Cabana::Halo<TEST_MEMSPACE>>(
MPI_COMM_WORLD, num_local, export_ids, export_ranks, neighbors );
else
halo = std::make_shared<Cabana::Halo<TEST_MEMSPACE>>(
MPI_COMM_WORLD, num_local, export_ids, export_ranks );
return halo;
}
template <class AoSoAType>
void checkGatherAoSoA( UniqueTestTag, AoSoAType data_host, const int my_size,
const int my_rank, const int num_local )
{
auto slice_int_host = Cabana::slice<0>( data_host );
auto slice_dbl_host = Cabana::slice<1>( data_host );
// check that the local data didn't change.
for ( int i = 0; i < my_size; ++i )
{
EXPECT_EQ( slice_int_host( 2 * i ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i, 1 ), my_rank + 1.5 );
EXPECT_EQ( slice_int_host( 2 * i + 1 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i + 1, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i + 1, 1 ), my_rank + 1.5 );
}
// Check that we got one element from everyone.
for ( int i = num_local; i < num_local + my_size; ++i )
{
// Self sends are first.
int send_rank = i - num_local;
if ( send_rank == 0 )
{
EXPECT_EQ( slice_int_host( i ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), my_rank + 1.5 );
}
else if ( send_rank == my_rank )
{
EXPECT_EQ( slice_int_host( i ), 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), 1.5 );
}
else
{
EXPECT_EQ( slice_int_host( i ), send_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), send_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), send_rank + 1.5 );
}
}
}
template <class AoSoAType>
void checkScatter( UniqueTestTag, AoSoAType data_host, const int my_size,
const int my_rank, const int num_local )
{
auto slice_int_host = Cabana::slice<0>( data_host );
auto slice_dbl_host = Cabana::slice<1>( data_host );
// Check that the local data was updated. Every ghost had a unique
// destination so the result should be doubled for those elements that
// were ghosted.
for ( int i = 0; i < my_size; ++i )
{
EXPECT_EQ( slice_int_host( 2 * i ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i, 1 ), my_rank + 1.5 );
EXPECT_EQ( slice_int_host( 2 * i + 1 ), 2 * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i + 1, 0 ), 2 * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i + 1, 1 ),
2 * ( my_rank + 1.5 ) );
}
// Check that the ghost data didn't change.
for ( int i = num_local; i < num_local + my_size; ++i )
{
// Self sends are first.
int send_rank = i - num_local;
if ( send_rank == 0 )
{
EXPECT_EQ( slice_int_host( i ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), my_rank + 1.5 );
}
else if ( send_rank == my_rank )
{
EXPECT_EQ( slice_int_host( i ), 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), 1.5 );
}
else
{
EXPECT_EQ( slice_int_host( i ), send_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), send_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), send_rank + 1.5 );
}
}
}
template <class AoSoAType>
void checkGatherSlice( UniqueTestTag, AoSoAType data_host, const int my_size,
const int my_rank, const int num_local )
{
auto slice_int_host = Cabana::slice<0>( data_host );
auto slice_dbl_host = Cabana::slice<1>( data_host );
// Check that the local data remained unchanged.
for ( int i = 0; i < my_size; ++i )
{
EXPECT_EQ( slice_int_host( 2 * i ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i, 1 ), my_rank + 1.5 );
EXPECT_EQ( slice_int_host( 2 * i + 1 ), 2 * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i + 1, 0 ), 2 * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( 2 * i + 1, 1 ),
2 * ( my_rank + 1.5 ) );
}
// Check that the ghost data was updated.
for ( int i = num_local; i < num_local + my_size; ++i )
{
// Self sends are first.
int send_rank = i - num_local;
if ( send_rank == 0 )
{
EXPECT_EQ( slice_int_host( i ), 2 * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), 2 * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), 2 * ( my_rank + 1.5 ) );
}
else if ( send_rank == my_rank )
{
EXPECT_EQ( slice_int_host( i ), 2 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), 2 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), 3 );
}
else
{
EXPECT_EQ( slice_int_host( i ), 2 * ( send_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), 2 * ( send_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), 2 * ( send_rank + 1.5 ) );
}
}
}
template <class AoSoAType>
void checkGatherAoSoA( AllTestTag, AoSoAType data_host, const int my_size,
const int my_rank, const int num_local )
{
auto slice_int_host = Cabana::slice<0>( data_host );
auto slice_dbl_host = Cabana::slice<1>( data_host );
// check that the local data didn't change.
EXPECT_EQ( slice_int_host( 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 0, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( 0, 1 ), my_rank + 1.5 );
// Check that we got one element from everyone.
for ( int i = num_local; i < num_local + my_size; ++i )
{
// Self sends are first.
int send_rank = i - num_local;
if ( send_rank == 0 )
{
EXPECT_EQ( slice_int_host( i ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), my_rank + 1.5 );
}
else if ( send_rank == my_rank )
{
EXPECT_EQ( slice_int_host( i ), 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), 1.5 );
}
else
{
EXPECT_EQ( slice_int_host( i ), send_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), send_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), send_rank + 1.5 );
}
}
}
template <class AoSoAType>
void checkScatter( AllTestTag, AoSoAType data_host, const int my_size,
const int my_rank, const int num_local )
{
auto slice_int_host = Cabana::slice<0>( data_host );
auto slice_dbl_host = Cabana::slice<1>( data_host );
// Check that the local data was updated. Every ghost was sent to all of
// the ranks so the result should be multiplied by the number of ranks.
EXPECT_EQ( slice_int_host( 0 ), ( my_size + 1 ) * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( 0, 0 ),
( my_size + 1 ) * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( 0, 1 ),
( my_size + 1 ) * ( my_rank + 1.5 ) );
// Check that the ghost data didn't change.
for ( int i = num_local; i < num_local + my_size; ++i )
{
// Self sends are first.
int send_rank = i - num_local;
if ( send_rank == 0 )
{
EXPECT_EQ( slice_int_host( i ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), my_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), my_rank + 1.5 );
}
else if ( send_rank == my_rank )
{
EXPECT_EQ( slice_int_host( i ), 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), 1.5 );
}
else
{
EXPECT_EQ( slice_int_host( i ), send_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), send_rank + 1 );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), send_rank + 1.5 );
}
}
}
template <class AoSoAType>
void checkGatherSlice( AllTestTag, AoSoAType data_host, const int my_size,
const int my_rank, const int num_local )
{
auto slice_int_host = Cabana::slice<0>( data_host );
auto slice_dbl_host = Cabana::slice<1>( data_host );
// Check that the local data remained unchanged.
EXPECT_EQ( slice_int_host( 0 ), ( my_size + 1 ) * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( 0, 0 ),
( my_size + 1 ) * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( 0, 1 ),
( my_size + 1 ) * ( my_rank + 1.5 ) );
// Check that the ghost data was updated.
for ( int i = num_local; i < num_local + my_size; ++i )
{
// Self sends are first.
int send_rank = i - num_local;
if ( send_rank == 0 )
{
EXPECT_EQ( slice_int_host( i ), ( my_size + 1 ) * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ),
( my_size + 1 ) * ( my_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ),
( my_size + 1 ) * ( my_rank + 1.5 ) );
}
else if ( send_rank == my_rank )
{
EXPECT_EQ( slice_int_host( i ), ( my_size + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ), ( my_size + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ), ( my_size + 1 ) * 1.5 );
}
else
{
EXPECT_EQ( slice_int_host( i ),
( my_size + 1 ) * ( send_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 0 ),
( my_size + 1 ) * ( send_rank + 1 ) );
EXPECT_DOUBLE_EQ( slice_dbl_host( i, 1 ),
( my_size + 1 ) * ( send_rank + 1.5 ) );
}
}
}
template <class CommData>
void checkSizeAndCapacity( CommData comm_data, const int num_send,
const int num_recv, const double overalloc )
{
auto send_size = comm_data.sendSize();
auto recv_size = comm_data.receiveSize();
EXPECT_EQ( send_size, num_send );
EXPECT_EQ( recv_size, num_recv );
auto send_capacity = comm_data.sendCapacity();
auto recv_capacity = comm_data.receiveCapacity();
EXPECT_EQ( send_capacity, num_send * overalloc );
EXPECT_EQ( recv_capacity, num_recv * overalloc );
}
//---------------------------------------------------------------------------//
// Gather/scatter test.
template <class TestTag>
void testHalo( TestTag tag, const bool use_topology )
{
// Get my rank.
int my_rank = -1;
MPI_Comm_rank( MPI_COMM_WORLD, &my_rank );
// Get my size.
int my_size = -1;
MPI_Comm_size( MPI_COMM_WORLD, &my_size );
// Make a communication plan.
int num_local = tag.num_local;
auto halo = createHalo( tag, use_topology, my_size, num_local );
// Check the plan.
EXPECT_EQ( halo->numLocal(), num_local );
EXPECT_EQ( halo->numGhost(), my_size );
// Create particle data.
HaloData halo_data( *halo );
auto data = halo_data.createData( my_rank, num_local );
// Gather by AoSoA.
Cabana::gather( *halo, data );
// Compare against original host data.
auto data_host = halo_data.copyToHost();
checkGatherAoSoA( tag, data_host, my_size, my_rank, num_local );
// Scatter back the results,
auto slice_int = Cabana::slice<0>( data );
auto slice_dbl = Cabana::slice<1>( data );
Cabana::scatter( *halo, slice_int );
Cabana::scatter( *halo, slice_dbl );
Cabana::deep_copy( data_host, data );
checkScatter( tag, data_host, my_size, my_rank, num_local );
// Gather again, this time with slices.
Cabana::gather( *halo, slice_int );
Cabana::gather( *halo, slice_dbl );
Cabana::deep_copy( data_host, data );
checkGatherSlice( tag, data_host, my_size, my_rank, num_local );
}
//---------------------------------------------------------------------------//
// Gather/scatter test with persistent buffers.
template <class TestTag>
void testHaloBuffers( TestTag tag, const bool use_topology )
{
// Get my rank.
int my_rank = -1;
MPI_Comm_rank( MPI_COMM_WORLD, &my_rank );
// Get my size.
int my_size = -1;
MPI_Comm_size( MPI_COMM_WORLD, &my_size );
// Make a communication plan.
int num_local = tag.num_local;
auto halo = createHalo( tag, use_topology, my_size, num_local );
// Check the plan.
EXPECT_EQ( halo->numLocal(), num_local );
EXPECT_EQ( halo->numGhost(), my_size );
// Create particle data.
HaloData halo_data( *halo );
auto data = halo_data.createData( my_rank, num_local );
// Create send and receive buffers with an overallocation.
double overalloc = 3.0; // large value since very little is communicated.
auto gather = createGather( *halo, data, overalloc );
// Check sizes and capacities.
int num_send = tag.num_send;
int num_recv = tag.num_recv;
checkSizeAndCapacity( gather, num_send, num_recv, overalloc );
// Gather by AoSoA using preallocated buffers.
gather.apply();
// Compare against original host data.
auto data_host = halo_data.copyToHost();
checkGatherAoSoA( tag, data_host, my_size, my_rank, num_local );
// Scatter back the results, now with preallocated slice buffers.
auto slice_int = Cabana::slice<0>( data );
auto slice_dbl = Cabana::slice<1>( data );
auto scatter_int = createScatter( *halo, slice_int, overalloc );
auto scatter_dbl = createScatter( *halo, slice_dbl, overalloc );
scatter_int.apply();
scatter_dbl.apply();
Cabana::deep_copy( data_host, data );
checkScatter( tag, data_host, my_size, my_rank, num_local );
checkSizeAndCapacity( scatter_int, num_recv, num_send, overalloc );
checkSizeAndCapacity( scatter_dbl, num_recv, num_send, overalloc );
// Gather again, this time with slices.
slice_int = Cabana::slice<0>( data );
slice_dbl = Cabana::slice<1>( data );
auto gather_int = createGather( *halo, slice_int, overalloc );
auto gather_dbl = createGather( *halo, slice_dbl, overalloc );
gather_int.apply();
gather_dbl.apply();
Cabana::deep_copy( data_host, data );
checkGatherSlice( tag, data_host, my_size, my_rank, num_local );
checkSizeAndCapacity( gather_int, num_send, num_recv, overalloc );
checkSizeAndCapacity( gather_dbl, num_send, num_recv, overalloc );
// Now check the reserve/shrink functionality with AoSoA.
// This call should do nothing since the overallocation is still taken into
// account.
gather.shrinkToFit( true );
scatter_int.shrinkToFit( true );
scatter_dbl.shrinkToFit( true );
checkSizeAndCapacity( gather, num_send, num_recv, overalloc );
checkSizeAndCapacity( scatter_int, num_recv, num_send, overalloc );
checkSizeAndCapacity( scatter_dbl, num_recv, num_send, overalloc );
// After another shrink (now without any overallocation) sizes should have
// changed.
gather.shrinkToFit();
scatter_int.shrinkToFit();
scatter_dbl.shrinkToFit();
checkSizeAndCapacity( gather, num_send, num_recv, 1.0 );
checkSizeAndCapacity( scatter_int, num_recv, num_send, 1.0 );
checkSizeAndCapacity( scatter_dbl, num_recv, num_send, 1.0 );
// Last, increase the overallocation factor.
overalloc = 5.0;
gather_int.reserve( *halo, slice_int, overalloc );
gather_dbl.reserve( *halo, slice_dbl, overalloc );
scatter_int.reserve( *halo, slice_int, overalloc );
scatter_dbl.reserve( *halo, slice_dbl, overalloc );
checkSizeAndCapacity( gather_int, num_send, num_recv, overalloc );
checkSizeAndCapacity( gather_dbl, num_send, num_recv, overalloc );
checkSizeAndCapacity( scatter_int, num_send, num_recv, overalloc );
checkSizeAndCapacity( scatter_dbl, num_send, num_recv, overalloc );
}
//---------------------------------------------------------------------------//
// RUN TESTS
//---------------------------------------------------------------------------//
// test without collisions (each ghost is unique)
TEST( Halo, Unique )
{
testHalo( UniqueTestTag{}, true );
testHaloBuffers( UniqueTestTag{}, true );
}
TEST( Halo, UniqueNoTopo )
{
testHalo( UniqueTestTag{}, false );
testHaloBuffers( UniqueTestTag{}, false );
}
// tests with collisions (each ghost is duplicated on all ranks)
TEST( Halo, All )
{
testHalo( AllTestTag{}, true );
testHaloBuffers( AllTestTag{}, false );
}
TEST( Halo, AllNoTopo )
{
testHalo( AllTestTag{}, false );
testHaloBuffers( AllTestTag{}, false );
}
//---------------------------------------------------------------------------//
} // end namespace Test