Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91712458
gather.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 13, 18:28
Size
2 KB
Mime Type
text/x-python
Expires
Fri, Nov 15, 18:28 (2 d)
Engine
blob
Format
Raw Data
Handle
22312437
Attached To
R6746 RationalROMPy
gather.py
View Options
# Copyright (C) 2018-2020 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import
numpy
as
np
from
rrompy.utilities.base.types
import
Np1D
,
Np2D
,
List
,
ListAny
from
.base
import
COMM
,
poolSize
,
forcedSerial
,
allowParallelExecution
__all__
=
[
'listGather'
,
'arrayGatherv'
,
'matrixGatherv'
]
def
listGather
(
obj
:
ListAny
,
allow
:
bool
=
True
)
->
ListAny
:
"""Gather list from parallel cores."""
if
allow
:
allowParallelExecution
(
True
)
if
not
forcedSerial
()
and
poolSize
()
>
1
:
objList
=
COMM
.
allgather
(
obj
)
res
=
[]
for
dat
in
objList
:
res
+=
dat
return
res
return
obj
def
arrayGatherv
(
obj
:
Np1D
,
sizes
:
List
[
int
],
allow
:
bool
=
True
)
->
Np1D
:
"""Gather vector from parallel cores."""
if
allow
:
allowParallelExecution
(
True
)
if
not
forcedSerial
()
and
len
(
sizes
)
>
1
:
out
=
np
.
empty
(
np
.
sum
(
sizes
),
dtype
=
obj
.
dtype
)
COMM
.
Allgatherv
(
obj
,
[
out
,
sizes
])
return
out
return
obj
def
matrixGatherv
(
obj
:
Np2D
,
sizes
:
List
[
int
],
allow
:
bool
=
True
,
vertical
:
bool
=
False
)
->
Np2D
:
"""Gather matrix from parallel cores."""
if
allow
:
allowParallelExecution
(
True
)
if
not
forcedSerial
()
and
len
(
sizes
)
>
1
:
if
vertical
:
length
=
obj
.
shape
[
1
]
else
:
length
,
obj
=
obj
.
shape
[
0
],
obj
.
T
out
=
arrayGatherv
(
obj
.
flatten
(),
[
s
*
length
for
s
in
sizes
],
False
)
.
reshape
(
-
1
,
length
)
if
vertical
:
return
out
return
out
.
T
return
obj
Event Timeline
Log In to Comment