// bsp9a.cpp : Zwei Schleifen
// Matrix Initialisierung


#include "stdafx.h"

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

#include <omp.h>

using namespace System;
using namespace System::Diagnostics;

int main(array<System::String ^> ^args) {
	const int N = 200;
	double a[N][N];
	Stopwatch^ sw = gcnew Stopwatch;

	sw->Start();

		//Console::WriteLine("AnzThread: {0}", omp_get_num_threads());
	#pragma omp parallel for
		for (int i1=0; i1<N; i1++) {
			a[0][i1] = 0.0;
			for (int i2=0; i2<N; i2++) {
				//Console::WriteLine("AnzThread: {0}", omp_get_num_threads());
				a[0][i2] += a[i2][i1];
			}
		}

	sw->Stop();

	Console::WriteLine("Außen parallelisiert  time: {0} ", sw->Elapsed );

	sw->Reset();
	sw->Start();

	for (int i1=0; i1<N; i1++) {
		a[0][i1] = 0.0;
			// Hier werden jeweils 2 Threads erzeugt, insgesamt N*2
		#pragma omp parallel for
			for (int i2=0; i2<N; i2++) {
				//Console::WriteLine("AnzThread: {0}", omp_get_num_threads());
				a[0][i2] += a[i2][i1];
			}
	}

	sw->Stop();
	Console::WriteLine("Innen parallelisiert  time: {0} ", sw->Elapsed );


	sw->Reset();
	sw->Start();

	#pragma omp parallel for
	for (int i1=0; i1<N; i1++) {
		a[0][i1] = 0.0;
		#pragma omp parallel for
			for (int i2=0; i2<N; i2++) {
				//Console::WriteLine("AnzThread: {0}", omp_get_num_threads());
				a[0][i2] += a[i2][i1];
			}
	}

	sw->Stop();
	Console::WriteLine("Innen und Außen parallelisiert  time: {0} ", sw->Elapsed );

	Console::ReadLine();	

	return 0;
}
