Open main menu

CDOT Wiki β

Changes

GPU621/NoName

16 bytes added, 11:29, 24 November 2016
SPMD
An example of the SPMD programming model in STD Threads using an atomic barrier
#include <iostream> #include <iomanip> #include <cstdlib> #include <chrono> #include <vector> #include <thread> #include <atomic> using namespace std::chrono;
std::atomic<double> pi;
void reportTime(const char* msg, steady_clock::duration span) {
auto ms = duration_cast<milliseconds>(span);
std::cout << msg << " - took - " <<
ms.count() << " milliseconds" << std::endl;
} void run(int ID, double stepSize, int nthrds, int n) {
double x;
double sum = 0.0;
sum = sum * stepSize;
pi = pi + sum;
}
int main(int argc, char** argv) {
if (argc != 3) {
std::cerr << argv[0] << ": invalid number of arguments\n";
std::cout << "Press Enter key to exit ... ";
std::cin.get(c);
}
====Question & Awnser====
23
edits