// bsp5a.cpp : aufteilen in 4 Zwischensumme

#include "stdafx.h"

#include <omp.h>

// Überlauf  !!!!


int _tmain(int argc, _TCHAR* argv[])
{
	const int MAXTHREADS=4;

	int j;
	 long long summe, sum[MAXTHREADS];

	omp_set_num_threads(MAXTHREADS);
	
	for (int i=0; i<MAXTHREADS; ++i) sum[i]=0;
	summe=0;
	for (int i = 1; i <= 100000; ++i) {
		 summe+=i;
	}
	int k=sizeof(long long) ;
	printf("Summe: %ld   %d\n", summe );
	printf("k: %d\n", k );

#pragma omp parallel for private(j) shared(sum)
		for (long i = 1; i <= 100000; ++i) {
			int id = omp_get_thread_num();  // zusätzlicher Aufwand !!!
			//j=sum[id];
			//sum[id]= j + i+1;
			sum[id]+=  i;
		}
	summe=0;
	for (int i=0; i<MAXTHREADS; ++i) summe+=sum[i];
	
	printf("Summe: %f\n", (double)summe );

	char ch[200];
	gets(ch);
	

	return 0;

}

