Your First Parallax Application
Build a complete GPU-accelerated application from scratch
Step 1: Create the Source File
Create a file called my_first_app.cpp:
C++
my_first_app.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <execution>
int main() {
std::cout << "Parallax First Application" << std::endl;
std::vector<float> data(10000);
// Initialize data
for (size_t i = 0; i < data.size(); i++) {
data[i] = static_cast<float>(i);
}
// GPU acceleration with std::execution::par
// Parallax automatically handles memory coherence
std::for_each(std::execution::par,
data.begin(), data.end(),
[](float& x) { x *= 2.0f; });
std::cout << "Processed " << data.size() << " elements" << std::endl;
std::cout << "First element: " << data[0] << std::endl;
std::cout << "Last element: " << data.back() << std::endl;
std::cout << "Success!" << std::endl;
return 0;
}
Step 2: Compile
terminal
g++ -std=c++20 my_first_app.cpp -lparallax-runtime -o my_first_app
Step 3: Run
terminal
./my_first_app
Expected output:
output
Parallax First Application
Initialized 10000 elements
First element: 0
Last element: 9999
Success!