Skip to content
Snippets Groups Projects
Commit 289dce4d authored by Xinzhe Wu's avatar Xinzhe Wu
Browse files

add 2 examples

parent db422bac
No related branches found
No related tags found
No related merge requests found
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
./build
./build2
build
build2
./build3
./build4
build3
build4
build_juwels
./build_juwels
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
#include <omp.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int nthreads;
#pragma omp parallel
printf("Hello World from thread = [%d]\n", omp_get_thread_num());
}
#include <math.h>
#include <iostream>
#include <omp.h>
#include <chrono>
#define from 0.0f
#define to 2.0f
#define parts 999999999
#define step ((to - from) / parts)
#define x (from + (step / 2.0f))
int main()
{
double integralSum = 0;
int i;
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
#pragma omp parallel for reduction(+:integralSum)
for (i = 1; i < (parts+1); ++i)
{
integralSum = integralSum + (step * fabs(pow((x + (step * i)),2) + 4));
}
std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> time_span = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
std::cout << "Integral sum = " << integralSum << ", time = " << time_span.count() << " s." << std::endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment