|
|
|
@ -5,6 +5,7 @@ |
|
|
|
|
#include <omp.h> |
|
|
|
|
#include <iostream> |
|
|
|
|
#include "FPS.h" |
|
|
|
|
#include "Pendulum.h" |
|
|
|
|
#include <QOpenGLContext> |
|
|
|
|
#include <QOpenGLShaderProgram> |
|
|
|
|
#include <QOffscreenSurface> |
|
|
|
@ -12,7 +13,6 @@ |
|
|
|
|
Simulation::Simulation() { |
|
|
|
|
ups = new FPS; |
|
|
|
|
ups->setUpdateInterval(100); |
|
|
|
|
|
|
|
|
|
timer = new QTimer(this); |
|
|
|
|
QTimer::connect(timer, &QTimer::timeout, this, &Simulation::update); |
|
|
|
|
timer->setInterval(updateInterval); |
|
|
|
@ -33,19 +33,23 @@ void Simulation::initialize() { |
|
|
|
|
initializeOpenGLFunctions(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int maxWorkGroupCount[3]; |
|
|
|
|
int maxWorkGroupSize[3]; |
|
|
|
|
int maxWorkGroupInvocations; |
|
|
|
|
for (int i = 0; i < 3; i++){ |
|
|
|
|
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, i, maxWorkGroupCount + i); |
|
|
|
|
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, i, maxWorkGroupSize + i); |
|
|
|
|
// Read GPU Limits
|
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < 3; i++){ |
|
|
|
|
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, i, gpuLimits.maxWGCount + i); |
|
|
|
|
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, i, gpuLimits.maxWGSize + i); |
|
|
|
|
} |
|
|
|
|
glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, &gpuLimits.maxWGInvocations); |
|
|
|
|
|
|
|
|
|
printf("Max work group count: (%d, %d, %d)\n", gpuLimits.maxWGCount[0], gpuLimits.maxWGCount[1], gpuLimits.maxWGCount[2]); |
|
|
|
|
printf("Max work group size: (%d, %d, %d)\n", gpuLimits.maxWGSize[0], gpuLimits.maxWGSize[1], gpuLimits.maxWGSize[2]); |
|
|
|
|
printf("Max work group invocations (x * y * z): %d\n", gpuLimits.maxWGInvocations); |
|
|
|
|
} |
|
|
|
|
glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, &maxWorkGroupInvocations); |
|
|
|
|
|
|
|
|
|
// Shader
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
printf("Max work group count: (%d, %d, %d)\n", maxWorkGroupCount[0], maxWorkGroupCount[1], maxWorkGroupCount[2]); |
|
|
|
|
printf("Max work group size: (%d, %d, %d)\n", maxWorkGroupSize[0], maxWorkGroupSize[1], maxWorkGroupSize[2]); |
|
|
|
|
printf("Max work group invocations (x * y * z): %d\n", maxWorkGroupInvocations); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -62,18 +66,30 @@ void Simulation::update() { |
|
|
|
|
double newPotentialEnergy = 0; |
|
|
|
|
double newKineticEnergy = 0; |
|
|
|
|
|
|
|
|
|
#pragma omp parallel for |
|
|
|
|
for (int i = 0; i < pendula.size(); i++){ // NOLINT(*-loop-convert) // not ranged based for msvc
|
|
|
|
|
for (int k = 0; k < substeps; k++) |
|
|
|
|
pendula[i]->update(h, gravity); |
|
|
|
|
double localPotentialEnergy = pendula[i]->potentialEnergy(gravity); |
|
|
|
|
double localKineticEnergy = pendula[i]->kineticEnergy(); |
|
|
|
|
#pragma omp atomic |
|
|
|
|
newPotentialEnergy += localPotentialEnergy; |
|
|
|
|
#pragma omp atomic |
|
|
|
|
newKineticEnergy += localKineticEnergy; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OLD with CPUs
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
#pragma omp parallel for |
|
|
|
|
for (int i = 0; i < pendula.size(); i++){ // NOLINT(*-loop-convert) // not ranged based for msvc
|
|
|
|
|
for (int k = 0; k < substeps; k++) |
|
|
|
|
pendula[i]->update(h, gravity); |
|
|
|
|
double localPotentialEnergy = pendula[i]->potentialEnergy(gravity); |
|
|
|
|
double localKineticEnergy = pendula[i]->kineticEnergy(); |
|
|
|
|
#pragma omp atomic |
|
|
|
|
newPotentialEnergy += localPotentialEnergy; |
|
|
|
|
#pragma omp atomic |
|
|
|
|
newKineticEnergy += localKineticEnergy; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NEW with GPUs
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
potentialEnergy = newPotentialEnergy; |
|
|
|
|
kineticEnergy = newKineticEnergy; |
|
|
|
|
|
|
|
|
@ -92,6 +108,7 @@ void Simulation::clearPendula() { |
|
|
|
|
pendula.shrink_to_fit(); |
|
|
|
|
|
|
|
|
|
updateEnergy(); |
|
|
|
|
updateGPUData(); |
|
|
|
|
|
|
|
|
|
emit layoutChanged(); |
|
|
|
|
} |
|
|
|
@ -103,6 +120,7 @@ void Simulation::addPendula(const std::vector<Pendulum *> &add) { |
|
|
|
|
pendula.push_back(p); |
|
|
|
|
|
|
|
|
|
updateEnergy(); |
|
|
|
|
updateGPUData(); |
|
|
|
|
|
|
|
|
|
emit layoutChanged(); |
|
|
|
|
} |
|
|
|
@ -115,3 +133,7 @@ void Simulation::updateEnergy() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Simulation::updateGPUData() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|