exploiting openmp in the initial section of modelica models · two-phase-flow steam-water...

17
OpenMP in Modelica Models Exploiting OpenMP in the Initial Section of Modelica Models - Work in Progress - Javier Bonilla (a) , Luis J. Yebra (a) and Sebasti´ an Dormido (b) (a) CIEMAT-PSA, Centro de Investigaciones Energ´ eticas, MedioAmbientales y Tecnol´ogicas Plataforma Solar de Almer´ ıa, Almer´ ıa, Spain, {javier.bonilla,luis.yebra}@psa.es (b) UNED, Universidad Nacional de Educaci´ on a Distancia, Madrid, Spain, [email protected] 5 th of September, 2011 J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 1 / 17

Upload: lynga

Post on 03-May-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Exploiting OpenMP in the Initial Section of Modelica Models- Work in Progress -

Javier Bonilla(a), Luis J. Yebra(a) and Sebastian Dormido(b)

(a) CIEMAT-PSA, Centro de Investigaciones Energeticas, MedioAmbientales y TecnologicasPlataforma Solar de Almerıa, Almerıa, Spain, {javier.bonilla,luis.yebra}@psa.es

(b) UNED, Universidad Nacional de Educacion a Distancia, Madrid, Spain, [email protected]

5th of September, 2011

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 1 / 17

Page 2: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Index

1 Introduction

2 OpenMP

3 The DISS test facility

4 Initial Section Parallelization

5 Simulation Results

6 Conclusions and Future Work

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 2 / 17

Page 3: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Introduction

Introduction

Modern equation-based object-oriented (EOO) modelling languages arecontinuously increasing their expressiveness to model complex systems.However, the required computational effort to simulate is also increasing.

Commonly, EOO models are compiled as single-threaded executables nottaking advantage of the newest multi-core processors.

This work describes a straightforward parallelization method in the initialsection of the resulting C source code obtained from a Modelica model.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 3 / 17

Page 4: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

OpenMP

OpenMP - Introduction

OpenMP (Open Multi-Processing) is an application programming interface(API) for multi-platform (Unix and Microsoft Windows platforms)shared-memory parallel programming in C/C++ and Fortran.

Version Year Languages

1.0 1997 Fortran

1.0 1998 C/C++

2.0 2000 Fortran

2.0 2002 C/C++

2.5 2005 Fortran,C/C++

3.0 2008 Fortran,C/C++

3.1 2011 Fortran,C/C++

OpenMP is maintained by theOpenMP Architecture ReviewBoard (ARB).

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 4 / 17

Page 5: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

OpenMP

OpenMP - Features

Key concept - Multithreading

Core elements

Parallel control directives. Control the flow execution (i.e. parallel).

Work Sharing. Distribute the code among cores (i.e. parallel for dir.).

Synchronization. critical, atomic and barrier directives.

Run-time functions. Set and get run-time information.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 5 / 17

Page 6: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

The DISS test facility

La Plataforma Solar de Almerıa (PSA)

CIEMAT-PSA, a Spanish government research and test center, is thebiggest Europen research center devoted to solar concentratingtechnologies.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 6 / 17

Page 7: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

The DISS test facility

The DISS test facility

The DISS test facility is the first facility built in the world wheretwo-phase-flow steam-water processes in parabolic-trough collectors can bestudied under real solar conditions.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 7 / 17

Page 8: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

The DISS test facility

Parabolic-Trough Collectors (PTCs)

Main elements

Parabolic-trough receiver.

Absorber tube.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 8 / 17

Page 9: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

The DISS test facility

DISS Modelica model

Cont...

Water...

Tp

b...cl...p0...

Co

nt.

..

Wate

r...Tp

b...

cl...

p0

...

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

Water...

T p

b...cl...p0...

Tamb

Rad

InletTe...

InletPr...

mdot_...

Outle...

pout

Tout

mdotout

is_liquid

Tmout

pin

Inle

tTem

p_in

j

Inle

tPre

ssur.

..

mdot_

inj...

Model inputs

Ambient temperature

Direct solar radiation

1st PTC inlet flow

Mass flow

Flow temperature

Flow pressure

11th PTC injector

Mass flow

Flow temperature

Flow pressure

Initialization

Outlet pressure

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 9 / 17

Page 10: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

The DISS test facility

Simulator scheme

����������AB��CDC�E�FB��

��F�C���FB��

����ECD������DEC�CE�

�����������B���B��

�������������

�����FB��CD��FB��

����DEB��

�C� ����E�

��CEC��������

����E�����

AB����C�B�

�������B�DE

��E� �����B��

��E���C�

�C��DB����CB�

!"���������"�#���CD�ECB�$

%&�#���CD�ECB�

�����E�E���DC�CE�

����E�'��C�

��E��

#D(�C�CECB��

���E��!�#�$

������E�

!A��C&�����$

��E�

�C�

�����E�C)�&��D�����

���������E��

Cont...

Water...

Tp

b...cl...p0...

Co

nt.

..

Wate

r...Tp

b...

cl...p

0...

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

CCP_diss

Tamb Rad

Water...

T p

b...cl...p0...

Tamb

Rad

InletTe...

InletPr...

mdot_...

Outle...

pout

Tout

mdotout

is_liquid

Tmout

pin

Inle

tTem

p_in

j

Inle

tPre

ssur.

..

mdot_

inj..

.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 10 / 17

Page 11: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

The DISS test facility

Model Calibration

Calibration process

Exporting the DISSModelica model toMatlab/Simulink.

Using the Matlab GeneticAlgorithm Toolbox.

Multi-objective approach,minimizing the outputtemperature difference ineach PTC.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 11 / 17

Page 12: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Initial Section Parallelization

Initial Section Parallelization (1/2)

Procedure

1 Reference the OpenMP header (omp.h) in the dsmodel.c file (Listing 1).

2 Set the maximum number of threads (omp set num threads) (Listing 2).

3 Manually distribute the sentences among the threads (Listing 3).

4 Compile including the OpenMP library (-fopenmp in GNU compilers).

#inc l u d e <omp . h>

Listing 1. OpenMP header inclusion.

c on s t an t i n t NCores = 4 ;omp set num threads ( NCores ) ;

Listing 2. Setting the maximum number of threads.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 12 / 17

Page 13: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Initial Section Parallelization

Initial Section Parallelization (2/2)

#pragma omp p a r a l l e l{

#pragma omp s e c t i o n s{

#pragma omp s e c t i o n{. . . . . . . .. . . . . . . .T[0]= g e t I n i V a l u e ( in iT ime , ”Tem PTC1” ) ;T[1]= g e t I n i V a l u e ( in iT ime , ”Tem PTC2” ) ;. . . . . . . .. . . . . . . .

}#pragma omp s e c t i o n{. . . . . . . .. . . . . . . .p [0 ]= g e t I n i V a l u e ( in iT ime , ” Pres PTC1” ) ;p [1]= g e t I n i V a l u e ( in iT ime , ” Pres PTC2” ) ;. . . . . . . .. . . . . . . .

}

#pragma omp s e c t i o n{. . . . . . . .. . . . . . . .r [0 ]= g e t I n i V a l u e ( in iT ime , ”Rad PTC1” ) ;r [1 ]= g e t I n i V a l u e ( in iT ime , ”Rad PTC2” ) ;. . . . . . . .. . . . . . . .

}#pragma omp s e c t i o n{. . . . . . . .. . . . . . . .m[0]= g e t I n i V a l u e ( in iT ime , ”Mflow PTC1” ) ;m[1]= g e t I n i V a l u e ( in iT ime , ”Mflow PTC2” ) ;. . . . . . . .. . . . . . . .

}}

}. . . . . . . .. . . . . . . .

Listing 3. OpenMP parallel sections.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 13 / 17

Page 14: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Simulation Results

Simulation Statistic

The tests were performed using a Intelr CoreTM i5 CPU M540, 2.53GHz. Several tests were performed and mean execution times have beencalculated.

Kind of model Original Parallelized

Execution time (s) 170.727 151.415

Speedup 1 1.13

Initialization section exec. time (s) 31.231 11.127

Initialization section speedup 1 2.80

Calibration execution time 3 days 9 hours 3 days 4.5 hours

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 14 / 17

Page 15: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Simulation Results

Simulation Result - output DISS field temperature

Calibration

3 3.5 4 4.5 5 5.5

x 104

450

500

550

600

650

700

Time (s)

Te

mp

era

ture

(K

)

Real temperature

Simulated temperature

Validation

3.5 4 4.5 5 5.5 6 6.5

x 104

450

500

550

600

650

Time (s)

Te

mp

era

ture

(K

)

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 15 / 17

Page 16: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Conclusions and Future Work

Conclusions

OpenMP can be easily used to parallelize the initial section in theresulting C source code obtained from Modelica models.

A mean speedup of 1.13 was obtained in the whole simulation.

A mean speedup of 2.80 was obtained in the initial section.

The gain in speed was useful in simulation and calibration.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 16 / 17

Page 17: Exploiting OpenMP in the Initial Section of Modelica Models · two-phase-flow steam-water processes in parabolic-trough ... Modelica model to Matlab ... Study how to implement the

OpenMP in Modelica Models

Conclusions and Future Work

Future Work

Study how to implement the use of OpenMP directly in the Modelicacode.

Study how to take advantage of OpenMP in the integration process.

Take advantage of a 13-node cluster.

Consider the parallelization not only in simulation but in the geneticalgorithm calibration.

J. Bonilla et al. (CIEMAT-PSA) OpenMP in Modelica Models September 2011 17 / 17