// bsp5a.cpp : aufteilen in 4 Zwischensumme
#include "stdafx.h"
#include <omp.h>

using namespace System;

int main(array<System::String ^> ^args)  {
	const int MAXTHREADS=4;
	int j;
	int summe, sum[MAXTHREADS];
	omp_set_num_threads(MAXTHREADS);
	for (int i=0; i<MAXTHREADS; ++i) sum[i]=0;

	#pragma omp parallel for private(j) shared(sum)
		for (int i = 0; i < 10000; ++i) {
			int id = omp_get_thread_num();
			j=sum[id];
			sum[id]=j + i+1;
		}
	summe=0;
	for (int i=0; i<MAXTHREADS; ++i) summe+=sum[i];
	
	Console::WriteLine("Summe: {0}  ", summe );

	Console::ReadLine();

	return 0;
}
