Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63050335
universe.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
Fri, May 17, 10:57
Size
2 KB
Mime Type
text/x-c
Expires
Sun, May 19, 10:57 (2 d)
Engine
blob
Format
Raw Data
Handle
17725881
Attached To
rLAMMPS lammps
universe.cpp
View Options
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "mpi.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#include "universe.h"
#include "memory.h"
using
namespace
LAMMPS_NS
;
/* ----------------------------------------------------------------------
create & initialize the universe of processors in communicator
------------------------------------------------------------------------- */
Universe
::
Universe
(
LAMMPS
*
lmp
,
MPI_Comm
communicator
)
:
Pointers
(
lmp
)
{
version
=
(
char
*
)
"22 Jan 2008"
;
uworld
=
communicator
;
MPI_Comm_rank
(
uworld
,
&
me
);
MPI_Comm_size
(
uworld
,
&
nprocs
);
uscreen
=
stdout
;
ulogfile
=
NULL
;
nworlds
=
0
;
procs_per_world
=
NULL
;
root_proc
=
NULL
;
}
/* ---------------------------------------------------------------------- */
Universe
::~
Universe
()
{
memory
->
sfree
(
procs_per_world
);
memory
->
sfree
(
root_proc
);
}
/* ----------------------------------------------------------------------
add 1 or more worlds to universe
str == NULL -> add 1 world with all procs in universe
str = NxM -> add N worlds, each with M procs
str = P -> add 1 world with P procs
------------------------------------------------------------------------- */
void
Universe
::
add_world
(
char
*
str
)
{
int
n
,
nper
;
char
*
ptr
;
if
(
str
==
NULL
)
{
n
=
1
;
nper
=
nprocs
;
}
else
if
((
ptr
=
strchr
(
str
,
'x'
))
!=
NULL
)
{
*
ptr
=
'\0'
;
n
=
atoi
(
str
);
nper
=
atoi
(
ptr
+
1
);
}
else
{
n
=
1
;
nper
=
atoi
(
str
);
}
procs_per_world
=
(
int
*
)
memory
->
srealloc
(
procs_per_world
,(
nworlds
+
n
)
*
sizeof
(
int
),
"universe:procs_per_world"
);
root_proc
=
(
int
*
)
memory
->
srealloc
(
root_proc
,(
nworlds
+
n
)
*
sizeof
(
int
),
"universe:root_proc"
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
procs_per_world
[
nworlds
]
=
nper
;
if
(
nworlds
==
0
)
root_proc
[
nworlds
]
=
0
;
else
root_proc
[
nworlds
]
=
root_proc
[
nworlds
-
1
]
+
procs_per_world
[
nworlds
-
1
];
if
(
me
>=
root_proc
[
nworlds
])
iworld
=
nworlds
;
nworlds
++
;
}
}
/* ----------------------------------------------------------------------
check if total procs in all worlds = procs in universe
------------------------------------------------------------------------- */
int
Universe
::
consistent
()
{
int
n
=
0
;
for
(
int
i
=
0
;
i
<
nworlds
;
i
++
)
n
+=
procs_per_world
[
i
];
if
(
n
==
nprocs
)
return
1
;
else
return
0
;
}
Event Timeline
Log In to Comment