Open main menu

CDOT Wiki β

Changes

GPU621/Group 1

401 bytes added, 13:50, 31 March 2023
Example
// Print the cache line size
cout << "Cache line size: " << CACHE_LINE_SIZE << " bytes" << endl;
// Run the program using a single thread
cout << "Running program using a single thread" << endl;
high_resolution_clock::time_point start_time = high_resolution_clock::now();
for (int i = 0; i < NUM_ITERATIONS; i++) {
counter1.value++;
counter2.value++;
}
high_resolution_clock::time_point end_time = high_resolution_clock::now();
checkRuntime(start_time, end_time);
cout << "Counter 1: " << counter1.value << endl;
cout << "Counter 2: " << counter2.value << endl;
// Record Run the start timeprogram using multiple threads cout << "Running program using " << NUM_THREADS << " threads" << endl; counter1.value = 0; counter2.value = 0;  high_resolution_clock::time_point start_time = high_resolution_clock::now();
// Create two threads to increment the counters
thread t1(increment1);
thread t2(increment2);
 
// Wait for the threads to finish
t1.join();
t2.join();
  // Record the end time high_resolution_clock::time_point end_time = high_resolution_clock::now();  // Check the runtime of the program
checkRuntime(start_time, end_time);
 
// Print the final counter values
cout << "Counter 1: " << counter1.value << endl;
cout << "Counter 2: " << counter2.value << endl;
return 0;
}
 
</pre>