SHA256
first lab done
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <omp.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
unsigned sum(const unsigned* V, std::size_t n){
|
||||||
|
unsigned acc=0;
|
||||||
|
for(int i =0;i <n; i++){
|
||||||
|
acc+=V[i];
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned sum_par(const unsigned* V, std::size_t n){
|
||||||
|
unsigned acc=0;
|
||||||
|
#pragma omp parallel for reduction(+ : acc)
|
||||||
|
for(size_t i =0;i <n; i++){
|
||||||
|
acc+=V[i];
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv){
|
||||||
|
std::size_t n = 1u<<28;
|
||||||
|
auto data = std::make_unique<unsigned[]>(n);
|
||||||
|
#pragma omp parallel for
|
||||||
|
for(std::size_t i=0; i<n;++i){
|
||||||
|
data[i]=i;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto t0 = omp_get_wtime();
|
||||||
|
auto r = sum_par(data.get(),n);
|
||||||
|
auto t1 = omp_get_wtime();
|
||||||
|
printf("par res: :0x%x\n It took %g s \n",r,t1-t0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto t0 = omp_get_wtime();
|
||||||
|
auto r = sum(data.get(),n);
|
||||||
|
auto t1 = omp_get_wtime();
|
||||||
|
printf("res: :0x%x\n It took %g s \n",r,t1-t0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user