9
9
parentnoderank, nchildren,
10
10
maybepvalput!, createbranchchannels, nworkersactive, workersactive,
11
11
procs_node, leafrankfoldedtree,
12
- TopTreeNode, SubTreeNode, ProductSection, indexinproduct, dropleading
12
+ TopTreeNode, SubTreeNode, ProductSection, indexinproduct, dropleading,
13
+ nelements
13
14
end
14
15
15
16
macro testsetwithinfo (str,ex)
414
415
@test dropleading (ps) isa ProductSection
415
416
@test collect (dropleading (ps)) == [(4 ,1 ),(2 ,2 ),(3 ,2 )]
416
417
@test collect (dropleading (dropleading (ps))) == [(1 ,),(2 ,)]
418
+
419
+ ps = ProductSection ((1 : 5 ,2 : 4 ,1 : 3 ),5 : 8 );
420
+ @test dropleading (ps) isa ProductSection
421
+ @test collect (dropleading (ps)) == [(2 ,1 ),(3 ,1 )]
422
+ @test collect (dropleading (dropleading (ps))) == [(1 ,)]
423
+ end
424
+ @testset " nelements" begin
425
+ ps = ProductSplit ((1 : 5 ,2 : 4 ,1 : 3 ),7 ,3 );
426
+ @test nelements (ps,dim= 1 ) == 5
427
+ @test nelements (ps,dim= 2 ) == 3
428
+ @test nelements (ps,dim= 3 ) == 2
429
+ @test_throws ArgumentError nelements (ps,dim= 0 )
430
+ @test_throws ArgumentError nelements (ps,dim= 4 )
431
+
432
+ ps = ProductSection ((1 : 5 ,2 : 4 ,1 : 3 ),5 : 8 );
433
+ @test nelements (ps,1 ) == 4
434
+ @test nelements (ps,2 ) == 2
435
+ @test nelements (ps,3 ) == 1
436
+
437
+ ps = ProductSection ((1 : 5 ,2 : 4 ,1 : 3 ),5 : 11 );
438
+ @test nelements (ps,1 ) == 5
439
+ @test nelements (ps,2 ) == 3
440
+ @test nelements (ps,3 ) == 1
441
+
442
+ ps = ProductSection ((1 : 5 ,2 : 4 ,1 : 3 ),4 : 8 );
443
+ @test nelements (ps,1 ) == 5
444
+ @test nelements (ps,2 ) == 2
445
+ @test nelements (ps,3 ) == 1
446
+
447
+ ps = ProductSection ((1 : 5 ,2 : 4 ,1 : 3 ),4 : 9 );
448
+ @test nelements (ps,1 ) == 5
449
+ @test nelements (ps,2 ) == 2
450
+ @test nelements (ps,3 ) == 1
417
451
end
452
+
453
+ @test ParallelUtilities. _checknorollover ((),(),())
454
+ @test ParallelUtilities. c2l_rec (3 ,1 ,(),()) == 3
418
455
end ;
419
456
420
457
@testset " ReverseLexicographicTuple" begin
@@ -856,6 +893,13 @@ end;
856
893
@test_throws BoundsError (tree,16 ) nchildren (tree,16 )
857
894
end ;
858
895
end ;
896
+
897
+ @testset " fulltree-toptree indexing" begin
898
+ procs = 1 : 5
899
+ tree = SequentialBinaryTree (procs)
900
+ @test ParallelUtilities. toptree_to_fulltree_index (tree,3 ) == 3
901
+ @test ParallelUtilities. fulltree_to_toptree_index (tree,3 ) == 3
902
+ end
859
903
end
860
904
861
905
@testsetwithinfo " SegmentedOrderedBinaryTree" begin
@@ -1061,6 +1105,11 @@ end;
1061
1105
end ;
1062
1106
end ;
1063
1107
end
1108
+
1109
+ @testsetwithinfo " unsegmentedtree" begin
1110
+ @test ParallelUtilities. unsegmentedtree (SegmentedSequentialBinaryTree) == SequentialBinaryTree
1111
+ @test ParallelUtilities. unsegmentedtree (SegmentedOrderedBinaryTree) == OrderedBinaryTree
1112
+ end
1064
1113
end
1065
1114
1066
1115
@testsetwithinfo " RemoteChannelContainer" begin
@@ -1496,10 +1545,9 @@ end;
1496
1545
@test take! (pipe. selfchannels. out) == pval (rank,Int[1 ])
1497
1546
end
1498
1547
1499
- function test_on_pipe (fn,iterator,pipe,result_expected)
1500
- progressrc = nothing
1548
+ function test_on_pipe (fn,iterator,pipe,result_expected,progressrc= nothing )
1501
1549
rank = 1
1502
- @test_throws ErrorException mapTreeNode (x-> error (" " ),iterator,rank,pipe,progressrc)
1550
+ @test_throws ErrorException mapTreeNode (x-> error (" fmap " ),iterator,rank,pipe,progressrc)
1503
1551
@test ! isready (pipe. selfchannels. out) # should not have any result as there was an error
1504
1552
@test isready (pipe. selfchannels. err)
1505
1553
@test take! (pipe. selfchannels. err) # error flag should be true
@@ -1508,6 +1556,10 @@ end;
1508
1556
@test ! isready (pipe. parentchannels. err)
1509
1557
@test ! isready (pipe. childrenchannels. out)
1510
1558
@test ! isready (pipe. childrenchannels. err)
1559
+ if progressrc isa RemoteChannel
1560
+ @test isready (progressrc)
1561
+ @test take! (progressrc) == (false ,false ,rank)
1562
+ end
1511
1563
1512
1564
mapTreeNode (fn,iterator,rank,pipe,progressrc)
1513
1565
@test isready (pipe. selfchannels. err)
@@ -1520,13 +1572,21 @@ end;
1520
1572
@test ! isready (pipe. parentchannels. err)
1521
1573
@test ! isready (pipe. childrenchannels. out)
1522
1574
@test ! isready (pipe. childrenchannels. err)
1575
+ if progressrc isa RemoteChannel
1576
+ @test isready (progressrc)
1577
+ @test take! (progressrc) == (true ,false ,rank)
1578
+ end
1523
1579
end
1524
1580
1525
1581
@testset " range" begin
1526
1582
iterator = 1 : 10
1527
1583
1528
1584
pipe = BranchChannel {Int,Int} (myid (),0 )
1529
1585
test_on_pipe (sum,iterator,pipe,sum (iterator))
1586
+
1587
+ pipe = BranchChannel {Int,Int} (myid (),0 )
1588
+ progress = RemoteChannel (()-> Channel {Tuple{Bool,Bool,Int}} (1 ))
1589
+ test_on_pipe (sum,iterator,pipe,sum (iterator),progress)
1530
1590
end
1531
1591
1532
1592
@testset " ProductSplit" begin
@@ -1652,7 +1712,7 @@ end;
1652
1712
end
1653
1713
end
1654
1714
1655
- end
1715
+ end # everwhere
1656
1716
1657
1717
@testset " reducedvalue" begin
1658
1718
@@ -1769,31 +1829,35 @@ end;
1769
1829
@test pipe. childrenchannels. err. where == 0
1770
1830
end
1771
1831
1832
+ strippedrank (t:: ParallelUtilities.ReductionNode ) = t. rank
1833
+ strippedrank (t:: Integer ) = t
1834
+
1772
1835
function testreduction (freduce:: Function ,pipe:: BranchChannel ,
1773
- ifsorted:: Ordering ,res_exp,rank,args... )
1836
+ ifsorted:: Ordering ,res_exp,rank,
1837
+ progressrc= nothing ,args... )
1774
1838
1775
1839
@test ! isready (pipe. parentchannels. out)
1776
1840
@test ! isready (pipe. parentchannels. err)
1777
1841
1778
- progressrc = nothing
1842
+ wait (@spawnat (pipe. p,
1843
+ putselfchildren! (pipe,ifsorted,rank,args... ) ) )
1844
+ reduceTreeNode (freduce,rank,pipe,ifsorted,progressrc)
1779
1845
1780
- try
1781
- wait (@spawnat (pipe. p,
1782
- putselfchildren! (pipe,ifsorted,rank,args... ) ) )
1783
- reduceTreeNode (freduce,rank,pipe,ifsorted,progressrc)
1784
- catch
1785
- rethrow ()
1786
- end
1787
1846
@test isready (pipe. parentchannels. out)
1788
1847
@test isready (pipe. parentchannels. err)
1789
1848
@test ! take! (pipe. parentchannels. err) # there should be no error
1790
1849
@test value (take! (pipe. parentchannels. out)) == res_exp
1791
1850
1851
+ if progressrc isa RemoteChannel
1852
+ @test isready (progressrc)
1853
+ @test take! (progressrc) == (false ,true ,strippedrank (rank))
1854
+ end
1855
+
1792
1856
# The pipe should be finalized at this point
1793
1857
testfinalized (rank,pipe)
1794
1858
end
1795
1859
1796
- end
1860
+ end # everywhere
1797
1861
1798
1862
for n = 1 : 2
1799
1863
@testset " Unsorted" begin
@@ -1807,6 +1871,19 @@ end;
1807
1871
pipe = BranchChannel {Int,Int} (myid (),n)
1808
1872
testreduction (sum,pipe,Unsorted (),res_exp,TopTreeNode (0 ))
1809
1873
1874
+ pipe = BranchChannel {Int,Int} (myid (),n)
1875
+ progress = RemoteChannel (()-> Channel {Tuple{Bool,Bool,Int}} (1 ))
1876
+ @test_throws ErrorException testreduction (
1877
+ x-> error (" fred" ),pipe,Unsorted (),
1878
+ res_exp,TopTreeNode (0 ),progress)
1879
+ @test isready (progress)
1880
+ @test take! (progress) == (false ,false ,0 )
1881
+
1882
+ pipe = BranchChannel {Int,Int} (myid (),n)
1883
+ progress = RemoteChannel (()-> Channel {Tuple{Bool,Bool,Int}} (1 ))
1884
+ testreduction (sum,pipe,Unsorted (),
1885
+ res_exp,TopTreeNode (0 ),progress)
1886
+
1810
1887
rc_parent = RemoteChannelContainer {Int} (1 )
1811
1888
p = workers ()[1 ]
1812
1889
0 commit comments