int FX_Init ( int SoundCard, int numvoices, int * numchannels, int * samplebits, int * mixrate, void * initdata ) { int status; int devicestatus; if ( FX_Installed ) { FX_Shutdown(); } if (SoundCard == ASS_AutoDetect) { #if 0 //defined __APPLE__ SoundCard = ASS_CoreAudio; #elif defined _WIN32 SoundCard = ASS_DirectSound; #elif defined HAVE_SDL SoundCard = ASS_SDL; #else SoundCard = ASS_NoSound; #endif } if (SoundCard < 0 || SoundCard >= ASS_NumSoundCards) { FX_SetErrorCode( FX_InvalidCard ); status = FX_Error; return status; } if (SoundDriver_IsPCMSupported(SoundCard) == 0) { // unsupported cards fall back to no sound SoundCard = ASS_NoSound; } status = FX_Ok; devicestatus = MV_Init( SoundCard, mixrate, numvoices, numchannels, samplebits, initdata ); if ( devicestatus != MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); status = FX_Error; } if ( status == FX_Ok ) { FX_Installed = TRUE; } return( status ); }
void TestArray(int argc, char* argv[]) { Log::Info("Test Array \n"); multiverso::SetCMDFlag("sync", true); MV_Init(&argc, argv); size_t array_size = 500; auto shared_array = MV_CreateTable(ArrayTableOption<int>(array_size)); Log::Info("Create tables OK. Rank = %d, worker_id = %d\n", MV_Rank(), MV_WorkerId()); std::vector<int> delta(array_size); for (int i = 0; i < array_size; ++i) delta[i] = static_cast<int>(i); int* data = new int[array_size]; int iter = 10 * (MV_Rank() + 10); for (int i = 0; i < iter; ++i) { shared_array->Add(delta.data(), array_size); shared_array->Add(delta.data(), array_size); shared_array->Add(delta.data(), array_size); shared_array->Get(data, array_size); shared_array->Get(data, array_size); shared_array->Get(data, array_size); if (iter < 100) { for (int k = 0; k < array_size; ++k) { CHECK (data[k] != delta[k] * (i + 1) * MV_NumWorkers()) ; } } } delete[] data; MV_ShutDown(); }
void TestmatrixPerformance(int argc, char* argv[], std::function<std::shared_ptr<WT>(int num_row, int num_col)>CreateWorkerTable, std::function<std::shared_ptr<ST>(int num_row, int num_col)>CreateServerTable, std::function<void(const std::shared_ptr<WT>& worker_table, const std::vector<int>& row_ids, const std::vector<float*>& data_vec, size_t size, const AddOption* option, int worker_id)> Add, std::function<void(const std::shared_ptr<WT>& worker_table, float* data, size_t size, int worker_id)> Get) { Log::ResetLogLevel(LogLevel::Info); Log::Info("Test Matrix\n"); Timer timmer; //multiverso::SetCMDFlag("sync", true); MV_Init(&argc, argv); int num_row = 1000000, num_col = 50; if (argc == 3){ num_row = atoi(argv[2]); } int size = num_row * num_col; int worker_id = MV_Rank(); int worker_num = MV_Size(); // test data float* data = new float[size]; float* delta = new float[size]; for (auto row = 0; row < num_row; ++row) { for (auto col = 0; col < num_col; ++col) { delta[row * num_col + col] = static_cast<float>(row * num_col + col); } } AddOption option; option.set_worker_id(worker_id); for (auto percent = 0; percent < 10; ++percent) for (auto turn = 0; turn < 10; ++turn) { //std::shuffle(unique_index.begin(), unique_index.end(), eng); if (worker_id == 0) { std::cout << "\nTesting: Get All Rows => Add " << percent + 1 << "0% Rows to Server => Get All Rows" << std::endl; } auto worker_table = CreateWorkerTable(num_row, num_col); auto server_table = CreateServerTable(num_row, num_col); MV_Barrier(); timmer.Start(); Get(worker_table, data, size, worker_id); std::cout << " " << 1.0 * timmer.elapse() / 1000 << "s:\t" << "get all rows first time, worker id: " << worker_id << std::endl; MV_Barrier(); std::vector<int> row_ids; std::vector<float*> data_vec; for (auto i = 0; i < num_row; ++i) { if (i % 10 <= percent && i % worker_num == worker_id) { row_ids.push_back(i); data_vec.push_back(delta + i * num_col); } } if (worker_id == 0) { std::cout << "adding " << percent + 1 << " /10 rows to matrix server" << std::endl; } if (row_ids.size() > 0) { Add(worker_table, row_ids, data_vec, num_col, &option, worker_id); } Get(worker_table, data, size, -1); MV_Barrier(); timmer.Start(); Get(worker_table, data, size, worker_id); std::cout << " " << 1.0 * timmer.elapse() / 1000 << "s:\t" << "get all rows after adding to rows, worker id: " << worker_id << std::endl; for (auto i = 0; i < num_row; ++i) { auto row_start = data + i * num_col; for (auto col = 0; col < num_col; ++col) { float expected = (float)i * num_col + col; float actual = *(row_start + col); if (i % 10 <= percent) { CHECK(expected == actual); } else { CHECK(0 == *(row_start + col)); } } } } MV_Barrier(); Log::ResetLogLevel(LogLevel::Info); Dashboard::Display(); Log::ResetLogLevel(LogLevel::Error); MV_ShutDown(); }
int FX_Init ( int SoundCard, int numvoices, int numchannels, int samplebits, unsigned mixrate ) { int status; int devicestatus; if ( FX_Installed ) { FX_Shutdown(); } if ( USER_CheckParameter( "ASSVER" ) ) { FX_SetErrorCode( FX_ASSVersion ); return( FX_Error ); } status = LL_LockMemory(); if ( status != LL_Ok ) { FX_SetErrorCode( FX_DPMI_Error ); return( FX_Error ); } FX_MixRate = mixrate; status = FX_Ok; FX_SoundDevice = SoundCard; switch( SoundCard ) { case SoundBlaster : case Awe32 : case ProAudioSpectrum : case SoundMan16 : case SoundScape : case SoundSource : case TandySoundSource : case UltraSound : devicestatus = MV_Init( SoundCard, FX_MixRate, numvoices, numchannels, samplebits ); if ( devicestatus != MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); status = FX_Error; } break; default : FX_SetErrorCode( FX_InvalidCard ); status = FX_Error; } if ( status != FX_Ok ) { LL_UnlockMemory(); } else { FX_Installed = TRUE; } return( status ); }