SHA256
before practice 3
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
// Project-local debug tasks
|
||||
//
|
||||
// For more documentation on how to configure debug tasks,
|
||||
// see: https://zed.dev/docs/debugger
|
||||
[
|
||||
|
||||
]
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <condition_variable>
|
||||
#include <stdio.h>
|
||||
#include <mutex>
|
||||
|
||||
class Barrier{
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
std::size_t count=0;
|
||||
std::size_t max_count=0;
|
||||
bool flushing = false;
|
||||
Barrier (size_t max_count){
|
||||
max_count=max_count;
|
||||
}
|
||||
void arrive_and_wait(){
|
||||
std::unique_lock lock(mtx);
|
||||
while(flushing)
|
||||
cv.wait(lock);
|
||||
if(++count<max_count)
|
||||
{
|
||||
while(! flushing)
|
||||
cv.wait(lock);
|
||||
}
|
||||
else{
|
||||
flushing = true;
|
||||
cv.notify_all();
|
||||
}
|
||||
if(--count==0){
|
||||
flushing = false;
|
||||
cv.notify_all();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
}
|
||||
+5
-5
@@ -29,7 +29,7 @@ unsigned sum_par_rr(const unsigned* V, std::size_t n){
|
||||
{
|
||||
int T = omp_get_num_threads();
|
||||
int t = omp_get_thread_num();
|
||||
partial_sums[t*CHACHE_LINE/sizeof(unsigned)]=0;
|
||||
//partial_sums[t*CHACHE_LINE/sizeof(unsigned)]=0;
|
||||
|
||||
for(size_t i = t;i <n; i+=T){
|
||||
partial_sums[t*CHACHE_LINE/sizeof(unsigned)]+=V[i];
|
||||
@@ -46,20 +46,20 @@ unsigned sum_par_rr(const unsigned* V, std::size_t n){
|
||||
|
||||
unsigned sum_par_rr_no_cache(const unsigned* V, std::size_t n){
|
||||
unsigned acc=0;
|
||||
unsigned* partial_sums = (unsigned*)calloc(omp_get_num_procs(),CHACHE_LINE);
|
||||
unsigned* partial_sums = (unsigned*)calloc(omp_get_num_procs(),sizeof(unsigned));
|
||||
#pragma omp parallel
|
||||
{
|
||||
int T = omp_get_num_threads();
|
||||
int t = omp_get_thread_num();
|
||||
// partial_sums[t*CHACHE_LINE/sizeof(unsigned)]=0;
|
||||
partial_sums[t*CHACHE_LINE/sizeof(unsigned)]=0;
|
||||
|
||||
for(size_t i = t;i <n; i+=T){
|
||||
partial_sums[t*CHACHE_LINE/sizeof(unsigned)]+=V[i];
|
||||
partial_sums[t]+=V[i];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0;i<omp_get_num_procs();i++){
|
||||
acc+=partial_sums[i*CHACHE_LINE/sizeof(unsigned)];
|
||||
acc+=partial_sums[i];
|
||||
}
|
||||
|
||||
return acc;
|
||||
|
||||
Reference in New Issue
Block a user