Refine Table factory
This commit is contained in:
Родитель
a27737e4d2
Коммит
d13119c324
|
@ -89,8 +89,7 @@ void TestArray(int argc, char* argv[]) {
|
|||
|
||||
size_t array_size = 50000000;
|
||||
|
||||
ArrayTableOption option{ array_size };
|
||||
ArrayWorker<float>* shared_array = MV_CreateTable<float>(option);
|
||||
ArrayWorker<float>* shared_array = MV_CreateTable(ArrayTableOption<float>(array_size));
|
||||
//ArrayWorker<float>* shared_array = new ArrayWorker<float>(50000000);
|
||||
//ArrayServer<float>* server_array = new ArrayServer<float>(50000000);
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ int MV_ServerIdToRank(int server_id);
|
|||
// \param option for table initiate
|
||||
// \return worker table pointer if this node is worker
|
||||
// otherwise return nullptr
|
||||
template <typename EleType, typename OptionType>
|
||||
typename trait::OptionTrait<EleType, OptionType>::WorkerTableType*
|
||||
MV_CreateTable(const OptionType& option) {
|
||||
auto table = table_factory::CreateTable<EleType>(option);
|
||||
template <typename TableOptionType>
|
||||
typename TableOptionType::WorkerTableType*
|
||||
MV_CreateTable(const TableOptionType& option) {
|
||||
auto table = table_factory::CreateTable(option);
|
||||
Zoo::Get()->Barrier();
|
||||
return table;
|
||||
}
|
||||
|
|
|
@ -7,15 +7,14 @@
|
|||
|
||||
namespace multiverso {
|
||||
|
||||
struct ArrayTableOption {
|
||||
size_t size;
|
||||
};
|
||||
template<typename EleType>
|
||||
struct ArrayTableOption;
|
||||
|
||||
template <typename T>
|
||||
class ArrayWorker : public WorkerTable {
|
||||
public:
|
||||
explicit ArrayWorker(size_t size);
|
||||
explicit ArrayWorker(const ArrayTableOption &option);
|
||||
explicit ArrayWorker(const ArrayTableOption<T> &option);
|
||||
// std::vector<T>& raw() { return table_; }
|
||||
|
||||
// Get all element, data is user-allocated memory
|
||||
|
@ -44,7 +43,7 @@ template <typename T>
|
|||
class ArrayServer : public ServerTable {
|
||||
public:
|
||||
explicit ArrayServer(size_t size);
|
||||
explicit ArrayServer(const ArrayTableOption& option);
|
||||
explicit ArrayServer(const ArrayTableOption<T> &option);
|
||||
|
||||
void ProcessAdd(const std::vector<Blob>& data) override;
|
||||
|
||||
|
@ -62,7 +61,12 @@ private:
|
|||
|
||||
};
|
||||
|
||||
DEFINE_TABLE_TRAIT_WITH_INIT_OPTION(ArrayTableOption, ArrayWorker, ArrayServer);
|
||||
template<typename T>
|
||||
struct ArrayTableOption {
|
||||
ArrayTableOption(size_t s) : size(s) {}
|
||||
size_t size;
|
||||
DEFINE_TABLE_TYPE(T, ArrayWorker, ArrayServer);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -122,17 +122,6 @@ private:
|
|||
std::unordered_map<Key, Val> table_;
|
||||
};
|
||||
|
||||
template <typename Key, typename Val>
|
||||
class KVTableHelper : public TableHelper {
|
||||
protected:
|
||||
WorkerTable* CreateWorkerTable() override{
|
||||
return new KVWorkerTable<Key, Val>();
|
||||
}
|
||||
ServerTable* CreateServerTable() override{
|
||||
return new KVServerTable<Key, Val>();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MULTIVERSO_KV_TABLE_H_
|
||||
|
|
|
@ -74,24 +74,6 @@ protected:
|
|||
std::vector<T> storage_;
|
||||
};
|
||||
|
||||
//older implementation
|
||||
template <typename T>
|
||||
class MatrixTableHelper : public TableHelper {
|
||||
public:
|
||||
MatrixTableHelper(integer_t num_row, integer_t num_col) : num_row_(num_row), num_col_(num_col){}
|
||||
~MatrixTableHelper() {}
|
||||
|
||||
protected:
|
||||
WorkerTable* CreateWorkerTable() override{
|
||||
return new MatrixWorkerTable<T>(num_row_, num_col_);
|
||||
}
|
||||
ServerTable* CreateServerTable() override{
|
||||
return new MatrixServerTable<T>(num_row_, num_col_);
|
||||
}
|
||||
integer_t num_row_;
|
||||
integer_t num_col_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MULTIVERSO_MATRIX_TABLE_H_
|
||||
|
|
|
@ -10,16 +10,14 @@ namespace multiverso {
|
|||
|
||||
namespace table_factory {
|
||||
|
||||
template <typename EleType, typename OptionType>
|
||||
typename trait::OptionTrait<EleType, OptionType>::WorkerTableType*
|
||||
CreateTable(const OptionType& option) {
|
||||
template <typename OptionType>
|
||||
typename OptionType::WorkerTableType* CreateTable(const OptionType& option) {
|
||||
if (Zoo::Get()->server_rank() >= 0) {
|
||||
table_factory::PushServerTable(
|
||||
new trait::OptionTrait<EleType, OptionType>::ServerTableType(option));
|
||||
new OptionType::ServerTableType(option));
|
||||
}
|
||||
if (Zoo::Get()->worker_rank() >= 0) {
|
||||
return reinterpret_cast<trait::OptionTrait<EleType, OptionType>::WorkerTableType*>
|
||||
(new trait::OptionTrait<EleType, OptionType>::WorkerTableType(option));
|
||||
return new OptionType::WorkerTableType(option);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -71,20 +71,10 @@ public:
|
|||
std::vector<Blob>* result) = 0;
|
||||
};
|
||||
|
||||
namespace trait {
|
||||
template<typename EleType, typename OptionType>
|
||||
struct OptionTrait;
|
||||
}
|
||||
|
||||
#define DEFINE_TABLE_TRAIT_WITH_INIT_OPTION(init_option, \
|
||||
worker_table_type, server_table_type) \
|
||||
namespace trait { \
|
||||
template<typename EleType> \
|
||||
struct OptionTrait<EleType, init_option> { \
|
||||
typedef worker_table_type<EleType> WorkerTableType; \
|
||||
typedef server_table_type<EleType> ServerTableType; \
|
||||
}; \
|
||||
}
|
||||
#define DEFINE_TABLE_TYPE(template_type, \
|
||||
worker_table_type, server_table_type) \
|
||||
typedef worker_table_type<template_type> WorkerTableType; \
|
||||
typedef server_table_type<template_type> ServerTableType;
|
||||
|
||||
} // namespace multiverso
|
||||
|
||||
|
|
|
@ -109,6 +109,12 @@
|
|||
<ClInclude Include="..\include\multiverso\table_interface.h">
|
||||
<Filter>system</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\multiverso\util\allocator.h">
|
||||
<Filter>util</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\multiverso\table_factory.h">
|
||||
<Filter>system</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="system">
|
||||
|
@ -209,5 +215,11 @@
|
|||
<ClCompile Include="net\mpi_net.cpp">
|
||||
<Filter>net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="util\allocator.cpp">
|
||||
<Filter>util</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="table_factory.cpp">
|
||||
<Filter>system</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -20,7 +20,7 @@ ArrayWorker<T>::ArrayWorker(size_t size) : WorkerTable(), size_(size) {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
ArrayWorker<T>::ArrayWorker(const ArrayTableOption &option)
|
||||
ArrayWorker<T>::ArrayWorker(const ArrayTableOption<T> &option)
|
||||
: ArrayWorker<T>(option.size) {
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ ArrayServer<T>::ArrayServer(size_t size) : ServerTable() {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
ArrayServer<T>::ArrayServer(const ArrayTableOption& option)
|
||||
ArrayServer<T>::ArrayServer(const ArrayTableOption<T> &option)
|
||||
: ArrayServer<T>(option.size) {
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче