Changes

Jump to: navigation, search

Debugging Parallel Programs in Visual Studio / Team Debug

3,118 bytes added, 00:58, 22 December 2017
Case C
==Case C==
We Each of these programs will use the following 2 programs to debugg 2 processesbe a separate project.  //Source1.cpp#include <iostream>#include <iomanip>#include <cstdlib>#include <chrono>#include <omp.h>#define NUM_THREADS 8using namespace std::chrono; // report system time//void reportTime(const char* msg, steady_clock::duration span) { auto ms = duration_cast<milliseconds>(span); std::cout << msg << " - took - " << ms.count() << " milliseconds" << std::endl;}
Each int main(int argc, char** argv) { if (argc != 2) { std::cerr << argv[0] << ": invalid number of these programs will be a separate projectarguments\n"; std::cerr << "Usage: " << argv[0] << " no_of_slices\n"; return 1; } int n = std::atoi(argv[1]); steady_clock::time_point ts, te;  // calculate pi by integrating the area under 1/(1 + x^2) in n steps ts = steady_clock::now(); int numThreads, f; double x, pi; double stepSize = 1.0 / (double)n; double sum[NUM_THREADS]; omp_set_num_threads(NUM_THREADS);#pragma omp parallel { int tid = omp_get_thread_num(); int nt = omp_get_num_threads(); if (tid == 0) numThreads = nt; sum[tid] = 0.0; for (int i = tid; i < n; i = i + nt) {  x = ((double)i + 0.5) * stepSize; sum[tid] += 4.0 / (1.0 + x * x); //std::cout << "THREAD" << tid << std::endl; } } int nt = omp_get_num_threads(); for (f = 0, pi = 0.0; f < numThreads; f++) { pi += sum[f] * stepSize; }  //pi = 4.0 * sum * stepSize; te = steady_clock::now();  std::cout << "n = " << n << std::fixed << std::setprecision(15) << "\n pi(exact) = " << 3.141592653589793 << "\n pi(calcd) = " << pi << std::endl; reportTime("Integration", te - ts);  // terminate char c; std::cout << "Press Enter key to exit ... "; std::cin.get(c);} //Source2.cpp#include <iostream>#include <iomanip>#include <cstdlib>#include <chrono>#include <omp.h>#define PAD 8#define NUM_THREADS 1using namespace std::chrono; // report system time//void reportTime(const char* msg, steady_clock::duration span) { auto ms = duration_cast<milliseconds>(span); std::cout << msg << " - took - " << ms.count() << " milliseconds" << std::endl;} int main(int argc, char** argv) { if (argc != 2) { std::cerr << argv[0] << ": invalid number of arguments\n"; std::cerr << "Usage: " << argv[0] << " no_of_slices\n"; return 1; } int n = std::atoi(argv[1]); steady_clock::time_point ts, te;  // calculate pi by integrating the area under 1/(1 + x^2) in n steps ts = steady_clock::now(); double x, pi = 0.0; double sum[NUM_THREADS][PAD]; double stepSize = 1.0 / (double)n; //double sumArr[8];  omp_set_num_threads(NUM_THREADS);#pragma omp parallel { int tid = omp_get_thread_num(); int nt = omp_get_num_threads();  for (int i = tid; i < n; i = i + nt) { x = ((double)i + 0.5) * stepSize; sum[tid][0] += 1.0 / (1.0 + x * x); //std::cout << "THREAD" << tid << std::endl; } }  for (int i = 0, pi = 0.0; i++;)pi += sum[i][0] * stepSize; //pi = 4.0 * sum * stepSize; te = steady_clock::now();  std::cout << "n = " << n << std::fixed << std::setprecision(15) << "\n pi(exact) = " << 3.141592653589793 << "\n pi(calcd) = " << pi << std::endl; reportTime("Integration", te - ts);  // terminate char c; std::cout << "Press Enter key to exit ... "; std::cin.get(c);}
There are two methods to debug multiple processes.
There are two methods to debug multiple processes.
Start Multiple Projects
28
edits

Navigation menu