// bsp7.cpp : SETI-Projekt
// Aufteilung 

#include "stdafx.h"

#include "math.h"  // sin
#include <windows.h>  // rand

#include <omp.h>



int _tmain(int argc, _TCHAR* argv[])
{
	const int MAX=4;
	int sum[MAX];
	int tid;
	int i, N;

	omp_set_num_threads(MAX);

	for (int i=0; i<MAX; i++) sum[i]=0;
	 N = 100000000;
	 N = 100000;
	 if (true) {

	  #pragma omp parallel for schedule(dynamic,1) private(i) 
		  for (i = 0; i < N; ++i)
			{
				tid = omp_get_thread_num();  // Pid
				if (tid<2) {
					int n = (int) (rand()*10);
					for (int j=0; j<(n); j++) double d = sin(33.44);
				}
				sum[tid]++;	
				//printf("Hello World from thread %d  Anz Threads: %d\n", tid, omp_get_num_threads());
			}

		 for (int i=0; i<MAX; i++) 
			 printf("ID: %d Summe: %d\n", i, sum[i]);
	 }
	 else {
		  // wenn aktiviert, dann ist die parallel for nur mit einem Thread 
		#pragma omp parallel private(i)
		{
			puts("loop oben");
			// #pragma omp for schedule(dynamic,1) nowait
			#pragma omp parallel for
				for (i = 0; i < N; ++i)
				{
					//puts("loop unten");
					tid = omp_get_thread_num();  // Pid

					int n = (int) (rand()/10000);
					for (int j=0; j<(n); j++) double d = sin(33.44);

					sum[tid]++;	
					printf("Hello World from thread %d  Anz Threads: %d\n", tid, omp_get_num_threads());
				}
		}

		for (int i=0; i<MAX; i++) 
		 printf("ID: %d Summe: %d\n", i, sum[i]);
	 }
	
	char ch[200];
	gets(ch);
	
	return 0;
}

