Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
solverstack
ScalFMM
Commits
af62847e
Commit
af62847e
authored
Nov 28, 2014
by
BRAMAS Berenger
Browse files
update mpi stuffs
parent
12ddcfcb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Src/Containers/FMpiBufferReader.hpp
View file @
af62847e
...
...
@@ -29,21 +29,35 @@
* finally use data pointer as you like
*/
class
FMpiBufferReader
:
public
FAbstractBufferReader
{
const
MPI_Comm
comm
;
//< Communicator needed by MPI_Pack functions
const
int
arrayCapacity
;
//< Allocated space
MPI_Comm
comm
;
//< Communicator needed by MPI_Pack functions
int
arrayCapacity
;
//< Allocated space
std
::
unique_ptr
<
char
[]
>
array
;
//< Allocated Array
int
currentIndex
;
public
:
/*Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferReader
(
const
MPI_Comm
inComm
,
const
int
inCapacity
=
512
)
:
explicit
FMpiBufferReader
(
const
MPI_Comm
inComm
=
MPI_COMM_WORLD
,
const
int
in
Default
Capacity
=
512
)
:
comm
(
inComm
),
arrayCapacity
(
inCapacity
),
array
(
new
char
[
inCapacity
]),
arrayCapacity
(
in
Default
Capacity
),
array
(
new
char
[
in
Default
Capacity
]),
currentIndex
(
0
){
FAssertLF
(
array
,
"Cannot allocate array"
);
}
/** Change the comm (or to set it later) */
void
setComm
(
const
MPI_Comm
inComm
){
comm
=
inComm
;
}
/** To change the capacity (but reset the head to 0) */
void
cleanAndResize
(
const
int
newCapacity
){
if
(
newCapacity
!=
arrayCapacity
){
arrayCapacity
=
newCapacity
;
array
.
reset
(
new
char
[
newCapacity
]);
}
currentIndex
=
0
;
}
/** Destructor
*/
virtual
~
FMpiBufferReader
(){
...
...
Src/Containers/FMpiBufferWriter.hpp
View file @
af62847e
...
...
@@ -29,25 +29,47 @@
* finally use data pointer as you like
*/
class
FMpiBufferWriter
:
public
FAbstractBufferWriter
{
const
MPI_Comm
mpiComm
;
//< Communicator needed by MPI_Pack functions
const
int
arrayCapacity
;
//< Allocated Space
MPI_Comm
mpiComm
;
//< Communicator needed by MPI_Pack functions
int
arrayCapacity
;
//< Allocated Space
std
::
unique_ptr
<
char
[]
>
array
;
//< Allocated Array
int
currentIndex
;
//< Currently filled space
/** Test and exit if not enought space */
void
assertRemainingSpace
(
const
size_t
requestedSpace
)
const
{
FAssertLF
(
int
(
currentIndex
+
requestedSpace
)
<=
arrayCapacity
,
"Error FMpiBufferWriter has not enough space"
);
void
expandIfNeeded
(
const
size_t
requestedSpace
)
{
if
(
arrayCapacity
<
int
(
currentIndex
+
requestedSpace
)
){
arrayCapacity
=
int
((
currentIndex
+
requestedSpace
+
1
)
*
1.5
);
char
*
arrayTmp
=
new
char
[
arrayCapacity
];
memcpy
(
arrayTmp
,
array
.
get
(),
sizeof
(
char
)
*
currentIndex
);
array
.
reset
(
arrayTmp
);
}
}
public:
/** Constructor with a default arrayCapacity of 512 bytes */
FMpiBufferWriter
(
const
MPI_Comm
inComm
,
const
int
inCapacity
=
1024
)
:
explicit
FMpiBufferWriter
(
const
MPI_Comm
inComm
,
const
int
in
Default
Capacity
=
1024
)
:
mpiComm
(
inComm
),
arrayCapacity
(
inCapacity
),
array
(
new
char
[
inCapacity
]),
arrayCapacity
(
in
Default
Capacity
),
array
(
new
char
[
in
Default
Capacity
]),
currentIndex
(
0
)
{}
/** Change the comm (or to set it later) */
void
setComm
(
const
MPI_Comm
inComm
){
mpiComm
=
inComm
;
}
/** To change the capacity (but reset the head to 0 if size if lower) */
void
resize
(
const
int
newCapacity
){
if
(
newCapacity
!=
arrayCapacity
){
arrayCapacity
=
newCapacity
;
char
*
arrayTmp
=
new
char
[
arrayCapacity
];
currentIndex
=
(
currentIndex
<
arrayCapacity
?
currentIndex
:
arrayCapacity
-
1
);
memcpy
(
arrayTmp
,
array
.
get
(),
sizeof
(
char
)
*
currentIndex
);
array
.
reset
(
arrayTmp
);
}
}
/** Destructor */
virtual
~
FMpiBufferWriter
(){
}
...
...
@@ -75,7 +97,7 @@ public:
/** Write data by packing cpy */
template
<
class
ClassType
>
void
write
(
const
ClassType
&
object
){
assertRemainingSpace
(
sizeof
(
ClassType
));
expandIfNeeded
(
sizeof
(
ClassType
));
MPI_Pack
(
const_cast
<
ClassType
*>
(
&
object
),
1
,
FMpi
::
GetType
(
object
),
array
.
get
(),
arrayCapacity
,
&
currentIndex
,
mpiComm
);
}
...
...
@@ -84,7 +106,7 @@ public:
*/
template
<
class
ClassType
>
void
write
(
const
ClassType
&&
object
){
assertRemainingSpace
(
sizeof
(
ClassType
));
expandIfNeeded
(
sizeof
(
ClassType
));
MPI_Pack
(
const_cast
<
ClassType
*>
(
&
object
),
1
,
FMpi
::
GetType
(
object
),
array
.
get
(),
arrayCapacity
,
&
currentIndex
,
mpiComm
);
}
...
...
@@ -101,7 +123,7 @@ public:
*/
template
<
class
ClassType
>
void
write
(
const
ClassType
*
const
objects
,
const
int
inSize
){
assertRemainingSpace
(
sizeof
(
ClassType
)
*
inSize
);
expandIfNeeded
(
sizeof
(
ClassType
)
*
inSize
);
MPI_Pack
(
const_cast
<
ClassType
*>
(
objects
),
inSize
,
FMpi
::
GetType
(
*
objects
),
array
.
get
(),
arrayCapacity
,
&
currentIndex
,
mpiComm
);
}
...
...
Src/Utils/FMpi.hpp
View file @
af62847e
...
...
@@ -68,6 +68,7 @@ public:
// FMM
TagFmmM2M
=
1000
,
TagFmmM2MSize
=
1500
,
TagFmmL2L
=
2000
,
TagFmmP2P
=
3000
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment