Input File ViennaIPD Application

0 downloads 0 Views 690KB Size Report
file language as well as the programming interface is dis- cussed in detail ..... [Online]. Available: http://www.lua.org. [8] “AngelScript. Manual.” [Online]. Available:.
ViennaIPD - An Input Control Language for Scientific Computing Josef Weinbub Karl Rupp Siegfried Selberherr Institute for Microelectronics, Technische Universit¨at Wien Gußhausstraße 27-29 / E360 A-1040 Vienna, Austria E-mail: {weinbub|rupp|selberherr}@iue.tuwien.ac.at

ABSTRACT #include "ipdP.h"

A powerful control language, named ViennaIPD, has been developed. The library based software is capable of reading complex input datasets which can be accessed from C/C++ applications by a programming interface. ViennaIPD supports a convenient C-like input file language, object oriented structuring of datasets, powerful inheritance mechanisms and a unit system. The input file language as well as the programming interface is discussed in detail.

int main(int argc, char** argv) { ipdChar *s; // Read a ViennaIPD input file ipdReadInputDeck(argv[1]); // Access data ipdGetStringByName("~a", &s); printf("Value of ~a: %s\n", s); // Manipulate data ipdSetIntegerByName("~SecA.a", 2); printf("Value of ~SecA.a set to: %d\n", 2);

1. 3.

4. a

return 0;

b

}

Application 2. a = "A short text"; b = 2.2; SecA { ext a = 1; d = 2 * a; }

a

SecB

a

d

INTRODUCTION Applications for scientific computing require a powerful control language to satisfy the need of control parameters, e.g. material properties, models to take into account, model parameters, process definitions, simulation modes, iteration schemes, and numerical behavior [1, 2, 3, 4]. As a result, control files grow in size, which results in decreased maintainability. Therefore a powerful control language has been developed as part of the MINIMOS-NT simulation software package [5, 6]. To enlarge the field of application the control language has been extracted, revisited, and packaged to be distributable as a standalone control language named ViennaIPD. ViennaIPD offers a powerful inheritance concept, unit conversion capabilities and the ability to directly access existing input files. The latter is especially of interest for reasons of post-processing simulation results. Figure 1 depicts a comprehensible overview how ViennaIPD is used.

SecA

d SubSecC

c

ViennaIPD

SecB : SecA { d = 3 * a; SubSecC { c = 1; } }

Input File Figure 1: ViennaIPD workflow. The application passes the filename of the input file to ViennaIPD (1.). The input file is used to populate the tree based datastructure (2.). The data can be accessed (3.) and manipulated (4.) by the application.

ViennaIPD provides a powerful input file language which aims to deal with the manifold parameter demands of simulation software. The library itself is written in C, however, applications can be based on either C or C++. The most fundamental element is a variable. To describe dependencies to other variables, a variable contains an expression, that is evaluated at runtime. Different variable types are supported as well as accessibility control. Furthermore, a section provides a means of structuring variables to enable associative variable definitions. A section holds an arbitrary set of variables and subsections.

Therefore any kind of data set hierarchy can be built. In this context, inheritance of sections is supported to enable, for example, reusability of section elements. Finally a large set of functions is provided to enable mathematical computations within the input files. The paper is organized as follows: The first section provides an overview of the ViennaIPD control language, whereas the second section outlines the programming interface. Furthermore, the third section depicts a use case example. Finally, the fourth section compares ViennaIPD to various other input control approaches.

34

However, this variable type can be used to temporarily store data, for example the result of a computation.

INPUT FILE SPECIFICATION The input file specification is based on a comprehensible language. The usage is similar to common programming languages, e.g. C. Additionally, object oriented features are provided to enable structuring of large data sets, i.e. inheritance mechanisms. Furthermore, a powerful unit system is provided which supports the validity of computations based on quantities.

Sections ViennaIPD supports structures of variables, so called sections, to manage large input files. A section is defined with 1

Variables An arbitrary number of variables can be defined. The general definition of a variable is 1

{ . . . }

The following snippet depicts a section named Solve with a read-only keyword variable. 1

S o l v e { maxStepSize = 1 e30 ; }

= ;

Sections can be nested to arbitrary depth must be a valid variable type. The available variable types are listed in Table 1. Note that if no is mentioned, the default key type is used. can be of any length, can contain capital and small letters, an underscore, and numbers. ext key aux

Description external variable - read- and writeable keyword variable - read-only (default) auxiliary variable - hidden

1 2 3 4 5

ViennaIPD enables also inheritance of sections. 1 2

However, the name must not begin with a number. An expression can be assigned to a variable by using the assignment operator = and a valid data-type (Table 2). Example a = true; a = 3; a = 3.1415; a = 4.3 + 3.1 j; a = 3.1415 "m/s"; a = "This is a string"; a = [1, "pi", 3 A];

1 2 3

1

1 2 3 4 5 6 7

key ext ext aux

some float some text x y a ex ey

= = = = = = =

3.3; ” some Text ” ; 32; 4; sqrt (x ∗ x + y ∗ y ); x / a; y / a;

2 3

Section : BaseSection1 ? expression1 , BaseSection1 ? expression2 , ... { }

Conditional inheritance is an extension to multiple inheritance. Several base sections can be specified for inheritance, an expression can be assigned to each one. The following snippet depicts the usage. 1 2

Lines 1,2,6,7 depict keyword variables. Hence, the assigned data can be accessed only, not altered. Lines 3,4 depict external variables, for which data can be accessed and altered. Line 5 outlines an application case for the auxiliary variable. This variable cannot be accessed by the programming interface, it is hidden.

BaseSection1 { a = 1; } BaseSection2 { b = 3; } DerivedSection : BaseSection1 , BaseSection2 ;

DerivedSection consists of two variables a and b inherited from BaseSection1 and BaseSection2, respectively. Additionally, conditional inheritance enables to inherit from sections based on specific conditions.

Table 2: Types of Data

The following snippet depicts a few examples which make use of the available variable types.

B a s e S e c t i o n { x1 = −3; } DerivedSection : BaseSection ;

DerivedSection is inherited from BaseSection. Consequently, DerivedSection contains all elements (variables and subsections) of BaseSection. Note, that the variables of BaseSection transparently exist in DerivedSection. Hence, if a variable in BaseSection changes, it changes in DerivedSection too. Furthermore, multiple inheritance is supported.

Table 1: Types of Variables

Type Boolean Integer Real Complex Quantity String Array

BaseSection { SubSection { SubSubSection { } } }

3 4 5

S w itch = 0 ; DerivedSection : BaseSection1 , B a s e S e c t i o n 2 ? ( S w itch > −1) , B a s e S e c t i o n 3 ? ( S w itch < 1 ) { }

DerivedSection is always inherited from BaseSection1. As Switch is 0, the conditions for BaseSection2 and BaseSection3 both hold.

35

Therefore, DerivedSection is additionally inherited from BaseSection2 and BaseSection3. If Switch is set to 2, DerivedSection is solely inherited from BaseSection1 and BaseSection2. Elements of inherited sections can be locally modified. 1 2 3 4 5

1 2 3 4

Q1 Q2 Q3 Q4

= = = =

3 ”A” ; 2 ”m” ; Q1 ∗ Q2 ; Q1 + Q2 ;

// OK // Error

PROGRAMMING INTERFACE

BaseSection { x = 1; y = 2; } DerivedSection : BaseSection { y = 4; }

The ViennaIPD Programming Interface is based on the C programming language. It provides an interface to the internal tree-based datastructures of ViennaIPD. Data can be traversed and accessed.

DerivedSection consists of the two variables x and y, where the variable x is inherited from BaseSection and the variable y is locally modified. So the variable DerivedSection.x equals 1 and the variable DerivedSection.y equals 4.

Interface Setup To be able to use the interface the ViennaIPD header file has to be included. 1

#i n c l u d e ” i p d . h”

Functions ViennaIPD enables the use of functions within input files. Functions can be used in expressions which are stored in variables.

The following code snippet depicts the initialization and the population of the datastructure from an input file. 1 2

1

= ( p a r a m e t e r s ) ;

3 4

An arbitrary number of parameters is supported. 1 2 3

a1 = f u n c 1 ( ) ; // 0 Parameter a2 = f u n c 2 ( 1 + 2 ) ; // 1 Parameter a3 = f u n c 3 ( ” h e l l o ” , a1 ) ; // 2 Parameter

ViennaIPD provides built-in functions, for example a large set of mathematical functions, e.g. sin(), pow(), sqrt(), to list a few of them. The following snippet depicts the computation of the sine of a complex number. 1

a = sin (4.42 + j ∗5.9);

5 6

Accessing Data Specialized getter and setter functions are provided to access and alter specific data types. The following code snippet depicts the reading and writing process based on these functions. 1 2 3

Furthermore support functions are provided, e.g. if() statement, conversion functions, array sizes, random number generator, to name a few.

4 5 6

ViennaIPD provides a powerful unit system. A unit is used in combination with the quantity datatype (Table 2) and consists of a valid unit name, of which many are provided. Quantity examples are: 1

2 3

q1 = 3 . 0 A; q2 = 5 . 5 ”V ∗ A” ; q3 = 4 . 2 ” kg m/ s s ” ;

Note that if a quantity is based on several unit names, double quotes have to be used (Lines 2,3). Unit names can be separated by a whitespace or an asterisk * (Line 2). The use of a single slash / indicates the beginning of the denominator. Hence, Line 3 represents the unit kg m/s2 . Quantity based computations are checked for semantically correct operations. Therefore, an error occurs, if two quantities with different units are summed up, as this would result in a mixed up physical quantity and, therefore, looses its validity. The following snippet outlines this behavior.

// declare a variable of type long ipdLong i ; // get the " c " integer value ipdGetIntegerByName ( ”∼c ” , &i ) ; // set the " c " integer value ipdSetIntegerByName ( ”∼c ” , 2 ) ;

Note the ∼ prefix, which indicates the root level of the datastructure hierarchy. Therefore variables can be accessed by absolute path addressing. For example accessing an integer variable named a within a section named BaseSection would be implemented by the following:

Units

1

// basic initialization i p d I n i t (NULL, NULL ) ; // create a new database i p d C r e a t e B a s e ( ” NameOfTheDatabase ” , 0 ) ; // read the inputfile ipdReadInputDeck ( a r g v [ 1 ] ) ;

2 3 4

// declare a variable of type long ipdLong i ; // get the " BaseSection " member value " a " ipdGetIntegerByName ( ”∼B a s e S e c t i o n . a ” , &i ) ;

Data can also be accessed without absolute addressing. This approach can be utilized by setting the current section. In relation to the previous example, the current section can be set to BaseSection as follows: 1

ipdSetCSByName ( ”∼B a s e S e c t i o n ” ) ;

Consequently, the data can be accessed directly 1 2 3

36

// get the integer data associated with the " a " // variable in the current section ipdGetIntegerByName ( ” a ” , &i ) ;

1 2 3 4

Iterators

COMPARISON

ViennaIPD provides iterators for convenient traversal of datastructures. The following snippet creates a new iterator on the root level

A comparison of different input control software packages is presented next. The comparison is based on the following features.

// define a new iterator ipdIterator t ∗ iNode = NULL; // set the iterator to traverse the root level i p d I t e r a t o r N e w A t R o o t S e c t i o n (&iNode , ipdANY ) ;

• convenient scripting language: The input language should be intuitive to scientists with slight background in programming. This results in an easy familiarization which, furthermore, reduces the overall implementation effort. • unit system: Typically scientific computing relies on physical quantities. Hence, it is of major interest to provide a computation facility which respects units and therefore enables a correct setup of physical quantities. • memory consumption: The memory consumption, for example the peak heap memory usage, should be kept small. • execution performance: The input control software should not decrease the overall execution performance of the scientific application.

All elements, e.g. variables, sections, on the root level can be traversed. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

// traverse as long as there are elements on // the root level while ( i p d I t e r a t o r I s V a l i d ( iNode ) ) { // retrieve the name of the current element i p d C o n s t S t r i n g itemName = i p d I t e r a t o r G e t I t e m N a m e ( iNode ) ; // is the element a variable ? i f ( i p d I t e r a t o r G e t T y p e ( iNode ) == ipdVARIABLE) p r i n t f ( ” v a r i a b l e : %s \n” , itemName ) ; // is the element a section ? else i f ( i p d I t e r a t o r G e t T y p e ( iNode ) == ipdSECTION ) p r i n t f ( ” s e c t i o n : %s \n” , itemName ) ; // increment the iterator to point // to the next element i p d I t e r a t o r D o N e x t ( iNode ) ; }

ViennaIPD is compared to the common scripting languages, Lua [7], AngelScript [8], and Python [9] in the following. All of the introduced software packages are supported with a convenient and intuitive language.

USE CASE EXAMPLE

Lua is a so called extension programming language which extends the functionality of mature programming languages, like C. Lua is a minimalistic, C based library which solely exists embedded in host applications. Lua can be used by different programming languages, e.g. C, C++, Fortran. AngelScript is a flexible cross-platform scripting library. C and C++ functions can be called within an AngelScript environment, hence code can be reused efficiently. Python is a mature programming language, but is also used as a scripting language. Python offers a C-API, and a C++ library for Python interoperability is also available [10]. All these input control languages offer interoperability with C and C++. Note, that most of the available programming languages, for example Fortran, are able to interoperate with C. In the following, benchmark results are presented and discussed. The test platform is a PC with an AMD Phenom II X4 - 965 CPU and 8GB of RAM. The operating system is a Gentoo Linux 64-bit with a 2.6.32 kernel.

The following depicts an exemplary ViennaIPD input file which contains a small dataset. 1 2 3 4 5 6 7 8 9 10 11

Electrons { uL300 = 0.143 uLImin300 = 0 . 0 0 8 Cref300 = 1 . 1 2 e17 CrefexpT = 3 . 2 ; } Holes : Electrons { uL300 = 460 uLImin300 = 45 Cref300 = 2 . 2 3 e17 }

”mˆ2/V∗ s ” ; ”mˆ2/V∗ s ” ; ”cmˆ−3” ;

”cmˆ2/V∗ s ” ; ”cmˆ2/V∗ s ” ; ”cmˆ−3” ;

Note the different units for the same parameters in Lines 2,3,8,9. The unit system automatically converts the units into SI units, hence, the quantities presented in Lines 8,9 are internally converted to: 0.046m2 /s · V and 0.0045m2 /s · V , respectively. Further note, that Electrons and Holes have different quantities for the Cref 300 parameter, which too get converted (Lines 4,10). Due to inheritance, both sections use the same value for the Cref expT parameter (Line 5). The following depicts the access of some data of the Holes section. 1 2 3 4 5 6 7 8

Table 3 depicts a comparison of the peak memory consumption and the execution time of a reference application which is driven by the introduced control languages. To depict the overhead of the input control languages, the standalone application, without any input control, is investigated too. The memory usage evaluation is based on Valgrind [11].

double ul , uLImin ; char∗ u n i t ; ipdGetRealQuantityByName ( ”∼H o l e s . uL300 ” , &ul , &u n i t ) ; ipdGetRealQuantityByName ( ”∼H o l e s . uLImin300 ” , &uLImin , &u n i t ) ; s t d : : c o u t

Suggest Documents