diff --git a/next/Test/main.cpp b/next/Test/main.cpp index 4387e3d..4d36295 100644 --- a/next/Test/main.cpp +++ b/next/Test/main.cpp @@ -108,6 +108,7 @@ void TestArray(int argc, char* argv[]) { void TestMomentum(int argc, char* argv[]) { Log::Info("Test smooth_gradient table \n"); + Log::ResetLogLevel(LogLevel::Debug); MultiversoInit(); @@ -141,50 +142,45 @@ void TestMomentum(int argc, char* argv[]) { MultiversoShutDown(); } - +#define ARRAY_SIZE 4683776 void TestMultipleThread(int argc, char* argv[]) { Log::Info("Test Multiple threads \n"); //Log::ResetLogLevel(LogLevel::Debug); MultiversoInit(&argc, argv); - ArrayWorker* shared_array = new ArrayWorker(10); - ArrayServer* server_array = new ArrayServer(10); + ArrayWorker* shared_array = new ArrayWorker(ARRAY_SIZE); + ArrayServer* server_array = new ArrayServer(ARRAY_SIZE); std::thread* m_prefetchThread = nullptr; MultiversoBarrier(); Log::Info("Create tables OK\n"); + std::vector delta(ARRAY_SIZE); while (true){ - // std::vector& vec = shared_array->raw(); - - // shared_array->Get(); - float data[10]; - - std::vector delta(10); - for (int i = 0; i < 10; ++i) - delta[i] = static_cast(i); - if (m_prefetchThread != nullptr && m_prefetchThread->joinable()) { m_prefetchThread->join(); delete m_prefetchThread; m_prefetchThread = nullptr; } - std::mt19937_64 eng{ std::random_device{}() }; - std::uniform_int_distribution<> dist{ 50, 500 }; - std::this_thread::sleep_for(std::chrono::milliseconds{ dist(eng) }); - shared_array->Add(delta.data(), 10); - Log::Info("Rank %d Add OK\n", MultiversoRank()); + std::fill(delta.begin(), delta.end(), 0); + for (int i = 0; i < ARRAY_SIZE; ++i) + { + std::mt19937_64 eng{ std::random_device{}() }; + std::uniform_real_distribution dist{ -1, 1 }; + delta[i] = dist(eng); + } m_prefetchThread = new std::thread([&](){ - std::mt19937_64 eng{ std::random_device{}() }; - std::uniform_int_distribution<> dist{ 50, 500 }; - std::this_thread::sleep_for(std::chrono::milliseconds{ dist(eng) }); - shared_array->Get(data, 10); + //std::mt19937_64 eng{ std::random_device{}() }; + //std::uniform_int_distribution<> dist{ 50, 500 }; + //std::this_thread::sleep_for(std::chrono::milliseconds{ dist(eng) }); + shared_array->Add(delta.data(), ARRAY_SIZE); + shared_array->Get(delta.data(), ARRAY_SIZE); Log::Info("Rank %d Get OK\n", MultiversoRank()); for (int i = 0; i < 10; ++i) - std::cout << data[i] << " "; std::cout << std::endl; + std::cout << delta[i] << " "; std::cout << std::endl; }); //shared_array->Get(data, 10);