@@ -43,6 +43,14 @@ function Base.showerror(io::IO,err::DecreasingIteratorError)
4343 print (io," all the iterators need to be strictly increasing" )
4444end
4545
46+ struct TaskNotPresentError{T,U} <: Exception
47+ t :: T
48+ task :: U
49+ end
50+ function Base. showerror (io:: IO ,err:: TaskNotPresentError )
51+ print (io," could not find the task $task in the list $t " )
52+ end
53+
4654struct BoundsErrorPS{T}
4755 ps :: T
4856 ind :: Int
@@ -438,23 +446,34 @@ end
438446
439447whichproc (iterators:: Tuple ,:: Nothing ,np:: Int ) = nothing
440448
441- # This function is necessary when we're changing np
442- function procrange_recast (ps:: ProductSplit ,np_new:: Int )
449+ # This function tells us the range of processors that would be involved
450+ # if we are to compute the tasks contained in the list ps on np_new processors.
451+ # The total list of tasks is contained in iterators, and might differ from
452+ # ps.iterators (eg if ps contains a subsection of the parameter set)
453+ function procrange_recast (iterators:: Tuple ,ps:: ProductSplit ,np_new:: Int )
443454
444455 if isempty (ps)
445456 return 0 : - 1 # empty range
446457 end
447458
448- procid_start = whichproc (ps. iterators,first (ps),np_new)
459+ procid_start = whichproc (iterators,first (ps),np_new)
460+ if procid_start === nothing
461+ throw (TaskNotPresentError (iterators,first (ps)))
462+ end
449463 if length (ps) == 1
450464 procid_end = procid_start
451465 else
452- procid_end = whichproc (ps. iterators,last (ps),np_new)
466+ procid_end = whichproc (iterators,last (ps),np_new)
467+ if procid_end === nothing
468+ throw (TaskNotPresentError (iterators,last (ps)))
469+ end
453470 end
454471
455472 return procid_start: procid_end
456473end
457474
475+ procrange_recast (ps:: ProductSplit ,np_new:: Int ) = procrange_recast (ps. iterators,ps,np_new)
476+
458477function localindex (ps:: ProductSplit{T} ,val:: T ) where {T}
459478 # Can carry out a binary search
460479
@@ -548,7 +567,7 @@ function pmapreduce_commutative(fmap::Function,freduce::Function,iterators::Tupl
548567
549568 procs_used = workersactive (iterators)
550569
551- num_workers = length (procs_used);
570+ num_workers_active = length (procs_used);
552571 hostnames = gethostnames (procs_used);
553572 nodes = nodenames (hostnames);
554573 procid_rank1_on_node = [procs_used[findfirst (isequal (node),hostnames)] for node in nodes];
@@ -582,7 +601,7 @@ function pmapreduce_commutative(fmap::Function,freduce::Function,iterators::Tupl
582601
583602 np_node = nprocs_node_dict[node]
584603
585- iterable_on_proc = evenlyscatterproduct (iterators,num_workers ,rank)
604+ iterable_on_proc = evenlyscatterproduct (iterators,num_workers_active ,rank)
586605
587606 @spawnat p begin
588607 try
@@ -714,7 +733,7 @@ function pmapreduce(fmap::Function,freduce::Function,iterable::Tuple,args...;kwa
714733
715734 procs_used = workersactive (iterable)
716735
717- num_workers = length (procs_used);
736+ num_workers_active = length (procs_used);
718737 hostnames = gethostnames (procs_used);
719738 nodes = nodenames (hostnames);
720739 procid_rank1_on_node = [procs_used[findfirst (isequal (node),hostnames)] for node in nodes];
@@ -748,7 +767,7 @@ function pmapreduce(fmap::Function,freduce::Function,iterable::Tuple,args...;kwa
748767
749768 np_node = nprocs_node_dict[node]
750769
751- iterable_on_proc = evenlyscatterproduct (iterable,num_workers ,rank)
770+ iterable_on_proc = evenlyscatterproduct (iterable,num_workers_active ,rank)
752771 @spawnat p begin
753772 try
754773 res = pval (p,fmap (iterable_on_proc,args... ;kwargs... ))
0 commit comments