@@ -37,7 +37,8 @@ function split_across_processors(arr₁,num_procs=nworkers(),proc_id=worker_rank
37
37
Iterators. take (Iterators. drop (arr₁,task_start- 1 ),num_tasks_on_proc)
38
38
end
39
39
40
- function split_product_across_processors (arr₁,arr₂,num_procs:: Integer = nworkers (),proc_id:: Integer = worker_rank ())
40
+ function split_product_across_processors (arr₁:: AbstractVector ,arr₂:: AbstractVector ,
41
+ num_procs:: Integer = nworkers (),proc_id:: Integer = worker_rank ())
41
42
# arr₁ will change faster
42
43
split_across_processors (Iterators. product (arr₁,arr₂),num_procs,proc_id)
43
44
end
@@ -46,7 +47,8 @@ function split_product_across_processors(arrs_tuple,num_procs::Integer=nworkers(
46
47
return split_across_processors (Iterators. product (arrs_tuple... ),num_procs,proc_id)
47
48
end
48
49
49
- function get_processor_id_from_split_array (arr₁,arr₂,(arr₁_value,arr₂_value):: Tuple ,num_procs)
50
+ function get_processor_id_from_split_array (arr₁:: AbstractVector ,arr₂:: AbstractVector ,
51
+ (arr₁_value,arr₂_value):: Tuple ,num_procs)
50
52
# Find the closest match in arrays
51
53
52
54
if (arr₁_value ∉ arr₁) || (arr₂_value ∉ arr₂)
@@ -87,43 +89,76 @@ function get_processor_id_from_split_array(arr₁,arr₂,(arr₁_value,arr₂_va
87
89
return proc_id
88
90
end
89
91
90
- function get_processor_range_from_split_array (arr₁,arr₂,modes_on_proc,num_procs)
92
+ function get_processor_id_from_split_array (iter,val:: Tuple ,num_procs)
93
+ for proc_id in 1 : num_procs
94
+ tasks_on_proc = split_across_processors (iter,num_procs,proc_id)
95
+ if val ∈ tasks_on_proc
96
+ return proc_id
97
+ end
98
+ end
99
+ return 0
100
+ end
101
+
102
+ function get_processor_range_from_split_array (arr₁:: AbstractVector ,arr₂:: AbstractVector ,
103
+ iter_section,num_procs:: Integer )
91
104
92
- if isempty (modes_on_proc )
105
+ if isempty (iter_section )
93
106
return 0 : - 1 # empty range
94
107
end
95
108
96
- tasks_arr = collect (modes_on_proc )
109
+ tasks_arr = collect (iter_section )
97
110
proc_id_start = get_processor_id_from_split_array (arr₁,arr₂,first (tasks_arr),num_procs)
98
111
proc_id_end = get_processor_id_from_split_array (arr₁,arr₂,last (tasks_arr),num_procs)
99
112
return proc_id_start: proc_id_end
100
113
end
101
114
102
- function get_index_in_split_array (modes_on_proc,(arr₁_value,arr₂_value))
103
- if isnothing (modes_on_proc)
115
+ function get_processor_range_from_split_array (iter,iter_section,num_procs:: Integer )
116
+
117
+ if isempty (iter_section)
118
+ return 0 : - 1 # empty range
119
+ end
120
+
121
+ tasks_arr = collect (iter_section)
122
+ proc_id_start = get_processor_id_from_split_array (iter,first (tasks_arr),num_procs)
123
+ proc_id_end = get_processor_id_from_split_array (iter,last (tasks_arr),num_procs)
124
+ return proc_id_start: proc_id_end
125
+ end
126
+
127
+ function get_index_in_split_array (iter_section,val:: Tuple )
128
+ if isnothing (iter_section)
104
129
return nothing
105
130
end
106
- for (ind,(t1,t2)) in enumerate (modes_on_proc )
107
- if (t1 == arr₁_value) && (t2 == arr₂_value)
131
+ for (ind,val_ind) in enumerate (iter_section )
132
+ if val_ind == val
108
133
return ind
109
134
end
110
135
end
111
136
nothing
112
137
end
113
138
114
- function procid_and_mode_index (arr₁,arr₂,(arr₁_value,arr₂_value),num_procs)
139
+ function procid_and_mode_index (arr₁:: AbstractVector ,arr₂:: AbstractVector ,
140
+ (arr₁_value,arr₂_value):: Tuple ,num_procs:: Integer )
115
141
proc_id_mode = get_processor_id_from_split_array (arr₁,arr₂,(arr₁_value,arr₂_value),num_procs)
116
142
modes_in_procid_file = split_product_across_processors (arr₁,arr₂,num_procs,proc_id_mode)
117
143
mode_index = get_index_in_split_array (modes_in_procid_file,(arr₁_value,arr₂_value))
118
144
return proc_id_mode,mode_index
119
145
end
120
146
121
- function mode_index_in_file (arr₁,arr₂,(arr₁_value,arr₂_value),num_procs,proc_id_mode)
147
+ function procid_and_mode_index (iter,val:: Tuple ,num_procs:: Integer )
148
+ proc_id_mode = get_processor_id_from_split_array (iter,val,num_procs)
149
+ modes_in_procid_file = split_across_processors (iter,num_procs,proc_id_mode)
150
+ mode_index = get_index_in_split_array (modes_in_procid_file,val)
151
+ return proc_id_mode,mode_index
152
+ end
153
+
154
+ function mode_index_in_file (arr₁:: AbstractVector ,arr₂:: AbstractVector ,
155
+ (arr₁_value,arr₂_value):: Tuple ,num_procs:: Integer ,proc_id_mode:: Integer )
122
156
modes_in_procid_file = split_product_across_processors (arr₁,arr₂,num_procs,proc_id_mode)
123
157
mode_index = get_index_in_split_array (modes_in_procid_file,(arr₁_value,arr₂_value))
124
158
end
125
159
126
- function procid_allmodes (arr₁,arr₂,iter,num_procs= nworkers_active (arr₁,arr₂))
160
+ function procid_allmodes (arr₁:: AbstractVector ,arr₂:: AbstractVector ,
161
+ iter,num_procs= nworkers_active (arr₁,arr₂))
127
162
procid = zeros (Int64,length (iter))
128
163
for (ind,mode) in enumerate (iter)
129
164
procid[ind] = get_processor_id_from_split_array (arr₁,arr₂,mode,num_procs)
133
168
134
169
workers_active (arr) = workers ()[1 : min (length (arr),nworkers ())]
135
170
136
- workers_active (arr₁,arr₂ ) = workers_active (Iterators. product (arr₁,arr₂ ))
171
+ workers_active (arrs ... ) = workers_active (Iterators. product (arrs ... ))
137
172
138
173
nworkers_active (args... ) = length (workers_active (args... ))
139
174
0 commit comments