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

#include "stdafx.h"

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

#include <omp.h>

using namespace System;

int main(array<System::String ^> ^args)  {
	const int MAX=2;
	int sum[MAX];
	int tid;
	int i, N;

	omp_set_num_threads(MAX);

	for (int i=0; i<MAX; i++) sum[i]=0;
	 N = 10000;
	 if (false) {

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

		 for (int i=0; i<MAX; i++) 
			 Console::WriteLine("ID: {0} Summe: {1}", i, sum[i]);
	 }
	 else {
		#pragma omp parallel for private(i)
		
			// #pragma omp for schedule(dynamic,1) 
				for (i = 0; i < N; ++i)
					{
					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]++;	
					//Console::WriteLine("Hello World from thread {0}  Anz Threads: {1}", tid, omp_get_num_threads());
				}
		

		for (int i=0; i<MAX; i++) 
		 Console::WriteLine("ID: {0} Summe: {1}", i, sum[i]);
	 }
	
	Console::ReadLine();
	return 0;
}
