// bsp6b.cpp : manuelle Aufteilung mit Threads, feste Angabe
#include "stdafx.h"

#include <omp.h>

using namespace System;

double calc(int id, int start, int points)
{
	return start*points;
}

int main(array<System::String ^> ^args)  {
	const int MAX=1000;
	int id, numThreads, start, points;
	double x;

	//omp_set_num_threads(8);  // statt num_threads(4)
	#pragma omp parallel private (id, numThreads)  num_threads(4) 
	{
		numThreads = omp_get_num_threads();
		id=omp_get_thread_num();
		points = MAX / numThreads;
		start = id * points;
		x = calc(id, start, points);
		Console::WriteLine(L"Thread id:{0}  numThreads: {1} start: {2}, points: {3}, x: {4}", 
			  id, numThreads, start, points, x);
	}		

	Console::WriteLine(L"Ende");
	Console::ReadLine();
	return 0;
}

















// 	1. Alternative
// #pragma omp parallel private (id, numThreads)  num_threads(4) 
// start ist nun eine shared Variable
// Ausgabe kritisch

// 	2. Alternative, die bessere
// #pragma omp parallel private (start, id, numThreads)  num_threads(4) 
// nun klappt es auch mit der start Variablen

