Add server table manage
This commit is contained in:
Родитель
d71e04451f
Коммит
2fd676dc77
|
@ -87,7 +87,9 @@ void TestArray(int argc, char* argv[]) {
|
|||
|
||||
MV_Init(&argc, argv);
|
||||
|
||||
ArrayTableInitOption option{ 50000000 };
|
||||
size_t array_size = 50000000;
|
||||
|
||||
ArrayTableInitOption option{ array_size };
|
||||
ArrayWorker<float>* shared_array = TableFactory::CreateTable<float>(option);
|
||||
//ArrayWorker<float>* shared_array = new ArrayWorker<float>(50000000);
|
||||
// ArrayServer<float>* server_array = new ArrayServer<float>(50000000);
|
||||
|
@ -95,10 +97,10 @@ void TestArray(int argc, char* argv[]) {
|
|||
MV_Barrier();
|
||||
Log::Info("Create tables OK\n");
|
||||
|
||||
std::vector<float> delta(50000000);
|
||||
for (int i = 0; i < 50000000; ++i)
|
||||
std::vector<float> delta(array_size);
|
||||
for (int i = 0; i < array_size; ++i)
|
||||
delta[i] = static_cast<float>(i);
|
||||
float* data = new float[50000000];
|
||||
float* data = new float[array_size];
|
||||
|
||||
int iter = 1000;
|
||||
|
||||
|
@ -106,7 +108,7 @@ void TestArray(int argc, char* argv[]) {
|
|||
// std::vector<float>& vec = shared_array->raw();
|
||||
|
||||
// shared_array->Get();
|
||||
shared_array->Get(data, 50000000);
|
||||
shared_array->Get(data, array_size);
|
||||
|
||||
for (int j = 0; j < 10; ++j)
|
||||
std::cout << data[j] << " "; std::cout << std::endl;
|
||||
|
@ -115,8 +117,8 @@ void TestArray(int argc, char* argv[]) {
|
|||
option.set_learning_rate(1 - 0.0001 * i);
|
||||
option.set_momentum(0.99);
|
||||
option.set_rho(0.01f);
|
||||
shared_array->Add(delta.data(), 50000000, &option);
|
||||
shared_array->Add(delta.data(), 50000000, &option);
|
||||
shared_array->Add(delta.data(), array_size, &option);
|
||||
shared_array->Add(delta.data(), array_size, &option);
|
||||
|
||||
}
|
||||
MV_ShutDown();
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
template <typename EleType, typename OptionType>
|
||||
static typename trait::OptionTrait<EleType, OptionType>::worker_table_type*
|
||||
CreateTable(const OptionType& option) {
|
||||
std::string typestr = typeid(EleType).name() + '_' +
|
||||
std::string typestr = typeid(EleType).name() + std::string("_") +
|
||||
trait::OptionTrait<EleType, OptionType>::type;
|
||||
return InnerCreateTable<EleType, OptionType>(typestr, option);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ public:
|
|||
std::string& type,
|
||||
worker_table_creater_t wt,
|
||||
server_table_creater_t st);
|
||||
static void FreeServerTables();
|
||||
private:
|
||||
template <typename EleType, typename OptionType>
|
||||
static typename trait::OptionTrait<EleType, OptionType>::worker_table_type*
|
||||
|
@ -32,7 +33,7 @@ private:
|
|||
CHECK(table_creaters_.find(type) != table_creaters_.end());
|
||||
|
||||
if (MV_ServerId() >= 0) {
|
||||
table_creaters_[type].second((void*)&table_args);
|
||||
table_factory::PushServerTable(table_creaters_[type].second((void*)&table_args));
|
||||
}
|
||||
if (MV_WorkerId() >= 0) {
|
||||
return reinterpret_cast<trait::OptionTrait<EleType, OptionType>::worker_table_type*>
|
||||
|
@ -54,6 +55,8 @@ struct TableRegister {
|
|||
TableFactory::RegisterTable(type, wt, st);
|
||||
}
|
||||
};
|
||||
void FreeServerTables();
|
||||
void PushServerTable(ServerTable*table);
|
||||
} // namespace table_factory
|
||||
|
||||
} // namespace multiverso
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "multiverso/dashboard.h"
|
||||
#include "multiverso/net.h"
|
||||
#include "multiverso/zoo.h"
|
||||
#include "multiverso/table_factory.h"
|
||||
|
||||
namespace multiverso {
|
||||
|
||||
|
@ -12,6 +13,7 @@ void MV_Init(int* argc, char* argv[]) {
|
|||
|
||||
void MV_ShutDown(bool finalize_net) {
|
||||
Zoo::Get()->Stop(finalize_net);
|
||||
table_factory::FreeServerTables();
|
||||
}
|
||||
|
||||
void MV_Barrier() { Zoo::Get()->Barrier(); }
|
||||
|
|
|
@ -18,6 +18,18 @@ void TableFactory::RegisterTable(
|
|||
table_creaters_[type] = std::make_pair(wt, st);
|
||||
}
|
||||
|
||||
namespace table_factory {
|
||||
std::vector<ServerTable*> g_server_tables;
|
||||
void FreeServerTables() {
|
||||
for (auto table : g_server_tables) {
|
||||
delete table;
|
||||
}
|
||||
}
|
||||
void PushServerTable(ServerTable*table) {
|
||||
g_server_tables.push_back(table);
|
||||
}
|
||||
}
|
||||
|
||||
#define MV_REGISTER_TABLE(type, worker_table_creater, \
|
||||
server_table_creater) \
|
||||
namespace table_factory { \
|
||||
|
|
Загрузка…
Ссылка в новой задаче