Commit 33dc5df3 authored by Christoph Gerum's avatar Christoph Gerum

Parallel examples

parents
#C++ autogenerated files
# Compiled Object files
*.slo
*.lo
*.o
# Compiled Dynamic libraries
*.so
*.dylib
# Compiled Static libraries
*.lai
*.la
*.a
#Emacs autogenerated files
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
#Linux specific ignores
.*
!.gitignore
*~
#No Archives
# It's better to unpack these files and commit the raw source because
# git has its own built in compression methods.
*.7z
*.jar
*.rar
*.zip
*.gz
*.bzip
*.bz2
*.xz
*.lzma
#packing-only formats
*.iso
*.tar
#package management formats
*.dmg
*.xpi
*.gem
*.egg
*.deb
*.rpm
\ No newline at end of file
File added
File added
#include <omp.h>
#include <stdio.h>
int main(int argc){
#pragma omp parallel
{
int ID = omp_get_thread_num();
printf(" Hello from %d\n", ID);
}
}
#include <omp.h>
#include <stdio.h>
static long num_steps = 100000000;
double step;
void main ()
{
int i, nthreads; double pi = 0.0;
step = 1.0/(double) num_steps;
#pragma omp parallel
{
int i, id, nthrds;
double x, sum = 0.0;
id = omp_get_thread_num();
nthrds = omp_get_num_threads();
for (i=id;i< num_steps; i=i+nthrds) {
x = (i+0.5)*step;
sum += 4.0/(1.0+x*x);
}
pi += sum * step;
}
printf("PI is aproximately %f\n", pi);
}
File added
File added
#include <stdio.h>
int main(int argc){
int ID = 0;
printf(" Hello from %d\n", ID);
}
#include <stdio.h>
static long num_steps = 100000000;
double step;
void main ()
{
int i; double x, pi, sum = 0;
step = 1.0/(double) num_steps;
for (i=0; i< num_steps; i=i+1) {
x = (i+0.5)*step;
sum += 4.0/(1.0+x*x);
}
pi = sum * step;
printf("PI is aproximately %1.12f\n", pi);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment