@@ -15,7 +15,7 @@ addprocs(workersused)
15
15
SequentialBinaryTree, OrderedBinaryTree, SegmentedSequentialBinaryTree,
16
16
parentnoderank, nchildren,
17
17
maybepvalput!, createbranchchannels, nworkersactive, workersactive,
18
- procs_node
18
+ procs_node, leafrankfoldedtree
19
19
end
20
20
21
21
macro testsetwithinfo (str,ex)
28
28
# Wrap a testset around this to get the result at the end
29
29
@testset " ParallelUtilities" begin
30
30
31
- @testset " ProductSplit" begin
31
+ @testsetwithinfo " ProductSplit" begin
32
32
33
33
various_iters = [(1 : 10 ,),(1 : 10 ,4 : 6 ),(1 : 10 ,4 : 6 ,1 : 4 ),(1 : 2 : 10 ,4 : 1 : 6 ),
34
34
(1 : 2 ,Base. OneTo (4 ),1 : 3 : 10 )]
379
379
end
380
380
end ;
381
381
382
- @testset " ReverseLexicographicTuple" begin
382
+ @testsetwithinfo " ReverseLexicographicTuple" begin
383
383
@testset " isless" begin
384
384
a = ParallelUtilities. ReverseLexicographicTuple ((1 ,2 ,3 ))
385
385
b = ParallelUtilities. ReverseLexicographicTuple ((2 ,2 ,3 ))
407
407
end
408
408
end ;
409
409
410
- @testset " utilities" begin
410
+ @testsetwithinfo " utilities" begin
411
411
@testset " workers active" begin
412
412
@test nworkersactive ((1 : 1 ,)) == 1
413
413
@test nworkersactive ((1 : 2 ,)) == min (2 ,nworkers ())
@@ -455,11 +455,13 @@ end;
455
455
pnode = workers ()[findall (isequal (node),hostnames)]
456
456
@test p1[node] == pnode
457
457
end
458
+ np4 = nprocs_node (p1)
459
+ @test np1 == np4
458
460
end
459
461
end ;
460
462
461
463
@testset " BinaryTree" begin
462
- @testset " BinaryTreeNode" begin
464
+ @testsetwithinfo " BinaryTreeNode" begin
463
465
@testset " Constructor" begin
464
466
p = workers ()[1 ]
465
467
b = BinaryTreeNode (p,p,0 )
@@ -727,6 +729,14 @@ end;
727
729
@test length (tree) == 12 + 3
728
730
end ;
729
731
732
+ @testset " leafrankfoldedtree" begin
733
+ @test leafrankfoldedtree (5 ,1 ) == 8
734
+ @test leafrankfoldedtree (5 ,2 ) == 9
735
+ @test leafrankfoldedtree (5 ,3 ) == 5
736
+ @test leafrankfoldedtree (5 ,4 ) == 6
737
+ @test leafrankfoldedtree (5 ,5 ) == 7
738
+ end ;
739
+
730
740
@testset " pid and parent" begin
731
741
for imax = 2 : 100
732
742
procs = 1 : imax
740
750
@test topnoderank == 1
741
751
@test tree[topnoderank] == ParallelUtilities. topnode (tree)
742
752
@test tree[1 ]. parent == 1
753
+ @test parentnoderank (tree,1 ) == 1
743
754
for (ind,rank) in enumerate (1 : mid)
744
755
node = tree[rank+ 1 ]
745
756
parentnode = tree[parentnoderank (tree,rank+ 1 )]
@@ -1213,15 +1224,17 @@ end;
1213
1224
@testset " at parent nodes" begin
1214
1225
1215
1226
# Put some known values on the self and children channels
1216
- function putselfchildren! (pipe:: BranchChannel ,:: Unsorted )
1217
- put! (pipe. selfchannels. out,0 )
1218
- put! (pipe. selfchannels. err,false )
1227
+ function putselfchildren! (pipe:: BranchChannel ,:: Unsorted ,rank= 1 )
1228
+ if rank >= 1
1229
+ put! (pipe. selfchannels. out,0 )
1230
+ put! (pipe. selfchannels. err,false )
1231
+ end
1219
1232
for i= 1 : nchildren (pipe)
1220
1233
put! (pipe. childrenchannels. out,i)
1221
1234
put! (pipe. childrenchannels. err,false )
1222
1235
end
1223
1236
end
1224
- function putselfchildren! (pipe:: BranchChannel{<:pval} ,:: Sorted )
1237
+ function putselfchildren! (pipe:: BranchChannel{<:pval} ,:: Sorted ,rank = 1 )
1225
1238
put! (pipe. selfchannels. out,pval (2 ,2 ))
1226
1239
put! (pipe. selfchannels. err,false )
1227
1240
N = nchildren (pipe)
@@ -1239,8 +1252,10 @@ end;
1239
1252
end
1240
1253
end
1241
1254
1242
- function clearerrors! (pipe:: BranchChannel )
1243
- take! (pipe. selfchannels. err)
1255
+ function clearerrors! (pipe:: BranchChannel ,rank= 1 )
1256
+ if rank >= 1
1257
+ take! (pipe. selfchannels. err)
1258
+ end
1244
1259
for i= 1 : nchildren (pipe)
1245
1260
take! (pipe. childrenchannels. err)
1246
1261
end
@@ -1249,27 +1264,26 @@ end;
1249
1264
@testset " reducedvalue" begin
1250
1265
1251
1266
function testreduction (freduce:: Function ,pipe:: BranchChannel ,
1252
- ifsorted:: Ordering ,res_exp)
1267
+ ifsorted:: Ordering ,res_exp,rank = 2 )
1253
1268
1254
1269
p = pipe. p
1255
- rank = 2
1256
1270
1257
1271
try
1258
- putselfchildren! (pipe,ifsorted)
1272
+ putselfchildren! (pipe,ifsorted,rank )
1259
1273
@test value (reducedvalue (freduce,rank,pipe,ifsorted)) == res_exp
1260
- clearerrors! (pipe)
1274
+ clearerrors! (pipe,rank )
1261
1275
1262
- @fetchfrom p putselfchildren! (pipe,ifsorted)
1276
+ @fetchfrom p putselfchildren! (pipe,ifsorted,rank )
1263
1277
@test value (@fetchfrom p reducedvalue (freduce,rank,pipe,ifsorted)) == res_exp
1264
- clearerrors! (pipe)
1278
+ clearerrors! (pipe,rank )
1265
1279
1266
- @fetchfrom p putselfchildren! (pipe,ifsorted)
1280
+ @fetchfrom p putselfchildren! (pipe,ifsorted,rank )
1267
1281
@test value (reducedvalue (freduce,rank,pipe,ifsorted)) == res_exp
1268
- clearerrors! (pipe)
1282
+ clearerrors! (pipe,rank )
1269
1283
1270
- putselfchildren! (pipe,ifsorted)
1284
+ putselfchildren! (pipe,ifsorted,rank )
1271
1285
@test value (@fetchfrom p reducedvalue (freduce,rank,pipe,ifsorted)) == res_exp
1272
- clearerrors! (pipe)
1286
+ clearerrors! (pipe,rank )
1273
1287
catch
1274
1288
rethrow ()
1275
1289
end
@@ -1279,7 +1293,8 @@ end;
1279
1293
@testset " Unsorted" begin
1280
1294
pipe = BranchChannel {Int,Int} (myid (),nchildren)
1281
1295
res_exp = sum (0 : nchildren)
1282
- testreduction (sum,pipe,Unsorted (),res_exp)
1296
+ testreduction (sum,pipe,Unsorted (),res_exp,2 )
1297
+ testreduction (sum,pipe,Unsorted (),res_exp,0 )
1283
1298
end
1284
1299
@testset " Sorted" begin
1285
1300
pipe = BranchChannel {pval,pval} (myid (),nchildren)
@@ -1291,6 +1306,13 @@ end;
1291
1306
testreduction (sum,pipe,Sorted (),res_exp)
1292
1307
end
1293
1308
end
1309
+
1310
+ # The top tree must have children by definition
1311
+ pipe = BranchChannel {Int,Int} (myid (),0 )
1312
+ putselfchildren! (pipe,Unsorted (),0 )
1313
+ err = ErrorException (" nodes with rank <=0 must have children" )
1314
+ @test_throws err reducedvalue (sum,0 ,pipe,Unsorted ())
1315
+ clearerrors! (pipe,0 )
1294
1316
end
1295
1317
1296
1318
@testset " reduceTreeNode" begin
@@ -1362,6 +1384,10 @@ end;
1362
1384
progress = RemoteChannel (()-> Channel {rettype} (1 ))
1363
1385
ParallelUtilities. indicatereduceprogress! (progress,10 )
1364
1386
@test take! (progress) == (false ,true ,10 )
1387
+
1388
+ @test isnothing (ParallelUtilities. indicatefailure! (nothing ,1 ))
1389
+ ParallelUtilities. indicatefailure! (progress,10 )
1390
+ @test take! (progress) == (false ,false ,10 )
1365
1391
end
1366
1392
end ;
1367
1393
@@ -1731,6 +1757,25 @@ end;
1731
1757
strexp = " could not find the task $((5 ,)) in the list $((1 : 4 ,)) "
1732
1758
@test String (take! (io)) == strexp
1733
1759
end
1760
+
1761
+ @testset " BranchChannel" begin
1762
+ io = IOBuffer ()
1763
+
1764
+ b = BranchChannel {Any,Any} (1 ,0 )
1765
+ show (io,b)
1766
+ strexp = " Leaf : 1 ← 1"
1767
+ @test String (take! (io)) == strexp
1768
+
1769
+ b = BranchChannel {Any,Any} (1 ,1 )
1770
+ show (io,b)
1771
+ strexp = " Branch: 1 ← 1 ← 1 child"
1772
+ @test String (take! (io)) == strexp
1773
+
1774
+ b = BranchChannel {Any,Any} (1 ,2 )
1775
+ show (io,b)
1776
+ strexp = " Branch: 1 ← 1 ⇇ 2 children"
1777
+ @test String (take! (io)) == strexp
1778
+ end
1734
1779
end ;
1735
1780
1736
1781
end ; # wrapper
0 commit comments