5 - Computational Engineering 2 [ID:10260]
50 von 665 angezeigt

We stopped at the chapter performance optimization with OpenMP.

So we looked at how we can look at different procedures for the example of numerical integration,

especially to avoid that there are conflicts with common variables when dividing into several sets.

And I think we arrived at that.

Here is another short example.

Let's go to the repeat.

So how can we do that for example?

We simply want to integrate this function here and what do we do?

We simply calculate the area below this function between the x-axis and the function graph.

By dividing the interval from the end of the start in different areas,

and we have to make it fine.

The finer we choose this step here, the more accurate we can approximate the whole thing.

Then the function value is calculated and multiplied by the width of this block and then all is summed up.

So we have the problem, we have to look, if we collect these,

I can't go through the detail anymore, I did that two weeks ago.

If we then collect the result when integrating this variable final res,

then there is a double value, then it can come to weather conditions,

when the whole thing is divided into several sets and it is not clear how this final res

has to be divided between the individual sets.

Well, one possibility is to see an array here for each set.

And each set then writes in its ID or writes under the ID that is assigned to it in the field

and thus is clearly guaranteed.

Then everything has to be summed up again at the end.

So we now define a new field, partial, and exactly with n entries.

So we would have n threads again.

And then each thread writes in there and then the parallel can write again.

So to speak, this is also in the sense now not a copied variable or not a copied size in the individual threads,

but it is a global variable defined over all threads,

but with individual positions from 0 to n, from 0 to n minus 1, which are correspondingly summed up.

And then it just has to be summed up again at the end. And the disadvantage is that we need this additional step.

Okay, we have done a step, we have gone one step further.

To prevent it from coming to such weather conditions,

that you can implicitly allow an atomic approach by introducing this pragma critical here

and thus it is ensured that at one point only one thread really accesses this variable local res.

Another variant, but it is even better, and that is with the help of the reduction operator.

Let's look at listing right away.

Exactly, so we are conducting here open NP, this variant of reduction with associative operators.

That means then it can, in such a tree, I showed that on a board two weeks ago,

in log n steps, as always, two neighbors, collect at the same time.

A, of course, as I mean, x1 plus x2 are summarized, x3 plus x4 are summarized, x5 plus x6 and x7 plus x8 in four sets.

And then you can put two sets to sleep and two other sets have to work

and then they summarize the intermediate results again. And then you can paralyze again.

And that's what you have to do, you give the operator what it should happen, what the associative operator should be,

in this case plus and the variable local res.

And yes, and with that, implicitly through this specification, an addition of access is ensured.

Okay, good. I don't think I've done that yet.

Let's just do it again, I don't know if I've already done it.

So, let's look at the following listing.

48 is an excerpt from an integration program similar to the previous example.

So we start again with a variable v, a double variable, and we put it on the city, on the city, on the starting point and the interval.

Teil einer Videoserie :

Zugänglich über

Offener Zugang

Dauer

01:14:04 Min

Aufnahmedatum

2018-05-14

Hochgeladen am

2019-04-05 02:59:03

Sprache

de-DE

Die Lehrveranstaltung soll Hintergrundwissen und Modelle zur Simulation vermitteln. Die Übungen sind dazu da, die Methoden am Computer zu implementieren und damit zu "experimentieren". Wir wollen dabei im speziellen diese Modelle verstehen und auf dem Computer praktisch umsetzen:

  • Zelluläre Automaten (Beutemodelle)

  • Populationsdynamik mithife gewöhnlicher Differentialgleichungen

  • Bewegliche Starrkörper

  • Temperaturverteilungen auf einer Platte

  • Strömungsmechanik mit Lattice-Boltzmann-Verfahren

Einbetten
Wordpress FAU Plugin
iFrame
Teilen