Created
December 12, 2013 00:27
-
-
Save retep998/7921181 to your computer and use it in GitHub Desktop.
Space Heater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GL/glew.h> | |
#include <GLFW/glfw3.h> | |
#include <string> | |
#include <iostream> | |
#include <thread> | |
#include <random> | |
#include <algorithm> | |
#include <chrono> | |
void fpu_thread() { | |
double x = 1; | |
for (;;) { | |
x = sin(cos(sin(cos(sin(cos(sin(cos(x)))))))); | |
} | |
} | |
void alu_thread() { | |
std::mt19937_64 rand; | |
for (;;) { | |
rand(); | |
} | |
} | |
void gpu_thread() { | |
glfwInit(); | |
glfwWindowHint(GLFW_VISIBLE, GL_FALSE); | |
auto context = glfwCreateWindow(1024, 1024, "", nullptr, nullptr); | |
glfwMakeContextCurrent(context); | |
glewInit(); | |
glLoadIdentity(); | |
glOrtho(0, 1, 1, 0, -1, 1); | |
GLuint vbo; | |
glGenBuffers(1, &vbo); | |
glBindBuffer(GL_ARRAY_BUFFER, vbo); | |
float a[] = { | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1, | |
0, 0, 1, 0, 1, 1, 0, 1 | |
}; | |
glBufferData(GL_ARRAY_BUFFER, sizeof(a), a, GL_STATIC_DRAW); | |
glEnableClientState(GL_VERTEX_ARRAY); | |
glVertexPointer(2, GL_FLOAT, 0, nullptr); | |
for (;;) { | |
for (int i = 0; i < 0x10; ++i) { | |
glDrawArrays(GL_QUADS, 0, 64); | |
} | |
glfwSwapBuffers(context); | |
glfwPollEvents(); | |
} | |
} | |
int main() { | |
int number; | |
std::cout << "Enter number of floating point threads: "; | |
std::cin >> number; | |
number = std::min(16, std::max(0, number)); | |
for (int i = 0; i < number; ++i) { | |
std::thread(fpu_thread).detach(); | |
} | |
std::cout << "Enter number of integer threads: "; | |
std::cin >> number; | |
number = std::min(16, std::max(0, number)); | |
for (int i = 0; i < number; ++i) { | |
std::thread(alu_thread).detach(); | |
} | |
std::cout << "Enter number of gpu threads: "; | |
std::cin >> number; | |
number = std::min(16, std::max(0, number)); | |
for (int i = 0; i < number; ++i) { | |
std::thread(gpu_thread).detach(); | |
} | |
for (;;) { | |
std::this_thread::sleep_for(std::chrono::seconds(1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment