Skip to content

Commit 778d0bd

Browse files
committed
1. remove static variable char_contiguous.
change Cereal_Func from namespace to class.
1 parent 55ea39e commit 778d0bd

File tree

10 files changed

+164
-144
lines changed

10 files changed

+164
-144
lines changed

include/Comm/Comm_Keys/Comm_Keys_31-sr.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#pragma once
77

8+
#include "../global/Cereal_Func.h"
9+
810
#include <vector>
911
#include <functional>
1012
#include <mpi.h>
@@ -15,14 +17,14 @@ namespace Comm
1517
template<typename Tkey, typename Tkeys_provide, typename Tkeys_require>
1618
class Comm_Keys_31
1719
{
18-
public:
20+
public:
1921
Comm_Keys_31(const MPI_Comm &mpi_comm_in);
2022

2123
std::vector<std::vector<Tkey>> trans(
2224
const Tkeys_provide &keys_provide_mine,
2325
const Tkeys_require &keys_require_mine);
2426

25-
protected:
27+
protected:
2628
void send_keys_require_mine(
2729
const Tkeys_require &keys_require_mine);
2830

@@ -40,6 +42,7 @@ class Comm_Keys_31
4042
int rank_size;
4143

4244
const int tag_keys = 99;
45+
Comm::Cereal_Func cereal_func;
4346
};
4447

4548
template<typename Tkey, typename Tkeys_provide, typename Tkeys_require>

include/Comm/Comm_Keys/Comm_Keys_31-sr.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#pragma once
77

88
#include "Comm_Keys_31-sr.h"
9-
#include "../global/Cereal_Func.h"
109

1110
#include <mpi.h>
1211
#include <thread>
@@ -109,14 +108,14 @@ void Comm_Keys_31<Tkey,Tkeys_provide,Tkeys_require>::send_keys_require_mine(
109108
cereal::BinaryOutputArchive ar(ss_isend);
110109
ar(keys_require_mine);
111110
}
112-
const std::size_t exponent_align = Cereal_Func::align_stringstream(ss_isend);
111+
const std::size_t exponent_align = this->cereal_func.align_stringstream(ss_isend);
113112
const std::string str_isend = ss_isend.str();
114113

115114
std::vector<MPI_Request> requests_isend(this->rank_size);
116115
for(int rank_recv_tmp=1; rank_recv_tmp<this->rank_size; ++rank_recv_tmp)
117116
{
118117
const int rank_recv = (this->rank_mine + rank_recv_tmp) % this->rank_size;
119-
Cereal_Func::mpi_isend(str_isend, exponent_align, rank_recv, this->tag_keys, this->mpi_comm, requests_isend[rank_recv]);
118+
this->cereal_func.mpi_isend(str_isend, exponent_align, rank_recv, this->tag_keys, this->mpi_comm, requests_isend[rank_recv]);
120119
std::this_thread::yield();
121120
}
122121

@@ -140,7 +139,7 @@ void Comm_Keys_31<Tkey,Tkeys_provide,Tkeys_require>::recv_require_intersection(
140139
std::vector<std::vector<Tkey>> &keys_trans_list)
141140
{
142141
Tkeys_require keys_require;
143-
const MPI_Status status_recv = Cereal_Func::mpi_recv( this->mpi_comm,
142+
const MPI_Status status_recv = this->cereal_func.mpi_recv( this->mpi_comm,
144143
keys_require);
145144
const int rank_require = status_recv.MPI_SOURCE;
146145
assert(this->tag_keys==status_recv.MPI_TAG);

include/Comm/Comm_Keys/Comm_Keys_32-sr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#pragma once
77

8+
#include "../global/Cereal_Func.h"
9+
810
#include <vector>
911
#include <functional>
1012
#include <mpi.h>
@@ -44,6 +46,7 @@ class Comm_Keys_32
4446
int rank_size;
4547

4648
const int tag_keys = 88;
49+
Comm::Cereal_Func cereal_func;
4750
std::shared_mutex lock_provide;
4851
};
4952

include/Comm/Comm_Keys/Comm_Keys_32-sr.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ void Comm_Keys_32<Tkey,Tkeys_provide,Tkeys_require>::send_keys_require_mine(
107107
cereal::BinaryOutputArchive ar(ss_isend);
108108
ar(keys_require_mine);
109109
}
110-
const std::size_t exponent_align = Cereal_Func::align_stringstream(ss_isend);
110+
const std::size_t exponent_align = this->cereal_func.align_stringstream(ss_isend);
111111
const std::string str_isend = ss_isend.str();
112112

113113
std::vector<MPI_Request> requests_isend(this->rank_size);
114114
for(int rank_recv_tmp=1; rank_recv_tmp<this->rank_size; ++rank_recv_tmp)
115115
{
116116
const int rank_recv = (this->rank_mine + rank_recv_tmp) % this->rank_size;
117-
Cereal_Func::mpi_isend(str_isend, exponent_align, rank_recv, this->tag_keys, this->mpi_comm, requests_isend[rank_recv]);
117+
this->cereal_func.mpi_isend(str_isend, exponent_align, rank_recv, this->tag_keys, this->mpi_comm, requests_isend[rank_recv]);
118118
std::this_thread::yield();
119119
}
120120

@@ -138,7 +138,7 @@ void Comm_Keys_32<Tkey,Tkeys_provide,Tkeys_require>::recv_require_intersection(
138138
std::vector<std::vector<Tkey>> &keys_trans_list)
139139
{
140140
Tkeys_require keys_require;
141-
const MPI_Status status_recv = Cereal_Func::mpi_recv( this->mpi_comm,
141+
const MPI_Status status_recv = this->cereal_func.mpi_recv( this->mpi_comm,
142142
keys_require);
143143
const int rank_require = status_recv.MPI_SOURCE;
144144
assert(this->tag_keys==status_recv.MPI_TAG);

include/Comm/Comm_Trans/Comm_Trans.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Comm_Trans
5151
Tdatas_recv &datas_recv);
5252

5353
private:
54-
void isend_data (const int rank_isend, const Tdatas_isend &datas_isend, std::string &str_isend, MPI_Request &request_isend, std::atomic<std::size_t> &memory_max_isend) const;
54+
void isend_data (const int rank_isend, const Tdatas_isend &datas_isend, std::string &str_isend, MPI_Request &request_isend, std::atomic<std::size_t> &memory_max_isend);
5555
void recv_data (Tdatas_recv &datas_recv, const MPI_Status status_recv, MPI_Message message_recv, std::atomic_flag &lock_set_value, std::atomic<std::size_t> &memory_max_isend);
5656
void post_process(
5757
std::vector<MPI_Request> &requests_isend,
@@ -67,6 +67,7 @@ class Comm_Trans
6767

6868
private:
6969
const int tag_data = 0;
70+
Comm::Cereal_Func cereal_func;
7071
};
7172

7273
}

include/Comm/Comm_Trans/Comm_Trans.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void Comm_Trans<Tkey,Tvalue,Tdatas_isend,Tdatas_recv>::isend_data(
112112
const Tdatas_isend &datas_isend,
113113
std::string &str_isend,
114114
MPI_Request &request_isend,
115-
std::atomic<std::size_t> &memory_max_isend) const
115+
std::atomic<std::size_t> &memory_max_isend)
116116
{
117117
std::stringstream ss_isend;
118118
{
@@ -132,10 +132,10 @@ void Comm_Trans<Tkey,Tvalue,Tdatas_isend,Tdatas_recv>::isend_data(
132132
ss_isend.rdbuf()->pubseekpos(0); // 返回size_item的占位,序列化真正的size_item值
133133
oar(size_item);
134134
} // end cereal::BinaryOutputArchive
135-
const std::size_t exponent_align = Cereal_Func::align_stringstream(ss_isend);
135+
const std::size_t exponent_align = this->cereal_func.align_stringstream(ss_isend);
136136
str_isend = ss_isend.str();
137137
memory_max_isend.store( std::max(str_isend.size()*sizeof(char), memory_max_isend.load()) );
138-
Cereal_Func::mpi_isend(str_isend, exponent_align, rank_isend, this->tag_data, this->mpi_comm, request_isend);
138+
this->cereal_func.mpi_isend(str_isend, exponent_align, rank_isend, this->tag_data, this->mpi_comm, request_isend);
139139
}
140140

141141

@@ -148,7 +148,7 @@ void Comm_Trans<Tkey,Tvalue,Tdatas_isend,Tdatas_recv>::recv_data (
148148
std::atomic_flag &lock_set_value,
149149
std::atomic<std::size_t> &memory_max_recv)
150150
{
151-
std::vector<char> buffer_recv = Cereal_Func::mpi_mrecv(message_recv, status_recv);
151+
std::vector<char> buffer_recv = this->cereal_func.mpi_mrecv(message_recv, status_recv);
152152

153153
std::stringstream ss_recv;
154154
ss_recv.rdbuf()->pubsetbuf(buffer_recv.data(), buffer_recv.size());

include/Comm/global/Cereal_Func.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,54 @@
55

66
#pragma once
77

8+
#include "MPI_Wrapper.h"
9+
810
#include <mpi.h>
911
#include <sstream>
1012
#include <vector>
1113

1214
namespace Comm
1315
{
1416

15-
namespace Cereal_Func
17+
class Cereal_Func
1618
{
19+
public:
20+
21+
// every 2^exponent_align char concatenate to 1 word
22+
inline std::size_t align_stringstream(std::stringstream &ss);
23+
1724
// Send str
18-
extern inline void mpi_send(const std::string &str, const std::size_t exponent_align, const int rank_recv, const int tag, const MPI_Comm &mpi_comm);
25+
inline void mpi_send(const std::string &str, const std::size_t exponent_align, const int rank_recv, const int tag, const MPI_Comm &mpi_comm);
1926

2027
// Send data
2128
template<typename... Ts>
22-
extern void mpi_send(const int rank_recv, const int tag, const MPI_Comm &mpi_comm,
29+
void mpi_send(const int rank_recv, const int tag, const MPI_Comm &mpi_comm,
2330
const Ts&... data);
2431

2532
// Isend str
26-
extern inline void mpi_isend(const std::string &str, const std::size_t exponent_align, const int rank_recv, const int tag, const MPI_Comm &mpi_comm, MPI_Request &request);
33+
inline void mpi_isend(const std::string &str, const std::size_t exponent_align, const int rank_recv, const int tag, const MPI_Comm &mpi_comm, MPI_Request &request);
2734

2835
// Isend data using temporary memory str
2936
template<typename... Ts>
30-
extern void mpi_isend(const int rank_recv, const int tag, const MPI_Comm &mpi_comm,
37+
void mpi_isend(const int rank_recv, const int tag, const MPI_Comm &mpi_comm,
3138
std::string &str, MPI_Request &request,
3239
const Ts&... data);
3340

41+
// Recv to return
42+
inline std::vector<char> mpi_recv(const MPI_Comm &mpi_comm, MPI_Status &status);
43+
3444
// Recv to data
3545
template<typename... Ts>
36-
extern MPI_Status mpi_recv(const MPI_Comm &mpi_comm,
46+
MPI_Status mpi_recv(const MPI_Comm &mpi_comm,
3747
Ts&... data);
3848

3949
// Mrecv to return
40-
extern inline std::vector<char> mpi_mrecv(MPI_Message &message_recv, const MPI_Status &status);
50+
inline std::vector<char> mpi_mrecv(MPI_Message &message_recv, const MPI_Status &status);
4151

42-
// every 2^exponent_align char concatenate to 1 word
43-
extern inline std::size_t align_stringstream(std::stringstream &ss);
44-
}
52+
private:
53+
54+
MPI_Wrapper::MPI_Type_Contiguous_Pool char_contiguous{MPI_CHAR};
55+
};
4556

4657
}
4758

0 commit comments

Comments
 (0)