Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88130517
one2many.cpp
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, Oct 16, 23:22
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Oct 18, 23:22 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
21719913
Attached To
rLAMMPS lammps
one2many.cpp
View Options
#include <mpi.h>
#include <stdlib.h>
#include "one2many.h"
#include "memory.h"
#include <map>
/* ---------------------------------------------------------------------- */
One2Many
::
One2Many
(
MPI_Comm
caller_comm
)
{
comm
=
caller_comm
;
MPI_Comm_rank
(
comm
,
&
me
);
MPI_Comm_size
(
comm
,
&
nprocs
);
memory
=
new
Memory
(
comm
);
hash
=
new
std
::
map
<
int
,
int
>
();
}
/* ---------------------------------------------------------------------- */
One2Many
::~
One2Many
()
{
delete
memory
;
delete
hash
;
}
/* ---------------------------------------------------------------------- */
void
One2Many
::
setup
(
int
nsrc_in
,
int
ndest
,
int
*
id
)
{
nsrc
=
nsrc_in
;
// store my local IDs in hash
hash
->
clear
();
for
(
int
i
=
0
;
i
<
ndest
;
i
++
)
hash
->
insert
(
std
::
pair
<
int
,
int
>
(
id
[
i
],
i
));
}
/* ---------------------------------------------------------------------- */
void
One2Many
::
scatter
(
double
*
src
,
int
n
,
double
*
dest
)
{
int
i
,
j
,
k
,
m
;
// allocate src on procs that don't have it
int
flag
=
0
;
if
(
src
==
NULL
)
{
src
=
(
double
*
)
memory
->
smalloc
(
n
*
nsrc
*
sizeof
(
double
),
"one2many:src"
);
flag
=
1
;
}
// broadcast src from 0 to other procs
MPI_Bcast
(
src
,
n
*
nsrc
,
MPI_DOUBLE
,
0
,
comm
);
// each proc loops over entire src
// if I own the global ID, copy src values into dest
std
::
map
<
int
,
int
>::
iterator
loc
;
for
(
m
=
1
;
m
<=
nsrc
;
m
++
)
{
loc
=
hash
->
find
(
m
);
if
(
loc
==
hash
->
end
())
continue
;
i
=
n
*
loc
->
second
;
j
=
3
*
(
m
-
1
);
if
(
n
==
1
)
dest
[
i
]
=
src
[
j
];
else
for
(
k
=
0
;
k
<
n
;
k
++
)
dest
[
i
++
]
=
src
[
j
++
];
}
// free locally allocated src
if
(
flag
)
memory
->
sfree
(
src
);
}
Event Timeline
Log In to Comment