monitor and threads
This commit is contained in:
47
src/Core/testing/OpenMPTest.cpp
Normal file
47
src/Core/testing/OpenMPTest.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "Core/Threads.h"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
class OpenMPThread : public Thread {
|
||||
public:
|
||||
void Run() override {
|
||||
#ifdef _OPENMP
|
||||
Thread::SetNumThreads(2);
|
||||
int max = Thread::GetNumThreads();
|
||||
std::cout << " OpenMP max threads in uLib::Thread: " << max << std::endl;
|
||||
|
||||
int shared_counter = 0;
|
||||
#pragma omp parallel reduction(+:shared_counter)
|
||||
{
|
||||
shared_counter += 1;
|
||||
}
|
||||
std::cout << " Parallel region executed with " << shared_counter << " threads." << std::endl;
|
||||
assert(shared_counter <= max);
|
||||
#else
|
||||
std::cout << " OpenMP not available, skipping parallel check." << std::endl;
|
||||
assert(Thread::GetNumThreads() == 1);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::cout << "Testing OpenMP compatibility..." << std::endl;
|
||||
#ifdef _OPENMP
|
||||
std::cout << " OpenMP is AVAILABLE." << std::endl;
|
||||
#else
|
||||
std::cout << " OpenMP is NOT available." << std::endl;
|
||||
#endif
|
||||
|
||||
OpenMPThread t;
|
||||
t.Start();
|
||||
t.Join();
|
||||
|
||||
std::cout << "OpenMP compatibility test finished!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user