ViennaIPD - An Input Control Language for Scientific Computing

Josef Weinbub Karl Rupp Siegfried Selberherr

Institute for Microelectronics, Technische Universit¨atWien 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 int main(int argc, char** argv) { been developed. The library based software is capable ipdChar *s;

// Read a ViennaIPD input file of reading complex input datasets which can be accessed ipdReadInputDeck(argv[1]); 1.

// Access data from C/C++ applications by a programming interface. 3. ipdGetStringByName("~a", &s); ViennaIPD supports a convenient C-like input file lan- printf("Value of ~a: %s\n", s);

// Manipulate data 4. guage, object oriented structuring of datasets, powerful ipdSetIntegerByName("~SecA.a", 2); a inheritance mechanisms and a unit system. The input printf("Value of ~SecA.a set to: %d\n", 2); return 0; b file language as well as the programming interface is dis- } cussed in detail. Application SecA a d

INTRODUCTION SecB a

Applications for scientific computing require a power- 2. d

a = "A short text"; ful control language to satisfy the need of control pa- SubSecC c b = 2.2; rameters, e.g. material properties, models to take into SecA { account, model parameters, process definitions, simu- ext a = 1; d = 2 * a; lation modes, iteration schemes, and numerical behav- } ViennaIPD ior [1, 2, 3, 4]. As a result, control files grow in size, SecB : SecA { which results in decreased maintainability. Therefore a d = 3 * a; SubSecC powerful control language has been developed as part of { c = 1; } 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 dis- Input File tributable as a standalone control language named Vi- ennaIPD. ViennaIPD offers a powerful inheritance con- Figure 1: ViennaIPD workflow. The application passes the cept, unit conversion capabilities and the ability to di- filename of the input file to ViennaIPD (1.). The input file rectly access existing input files. The latter is especially is used to populate the tree based datastructure (2.). The of interest for reasons of post-processing simulation re- data can be accessed (3.) and manipulated (4.) by the sults. Figure 1 depicts a comprehensible overview how application. ViennaIPD is used. ViennaIPD provides a powerful input file language which aims to deal with the manifold parameter de- mands of simulation software. The library itself is writ- Therefore any kind of data set hierarchy can be built. ten in C, however, applications can be based on either In this context, inheritance of sections is supported to C or C++. The most fundamental element is a vari- enable, for example, reusability of section elements. Fi- able. To describe dependencies to other variables, a nally a large set of functions is provided to enable math- variable contains an expression, that is evaluated at run- ematical computations within the input files. time. Different variable types are supported as well as The paper is organized as follows: The first section pro- accessibility control. Furthermore, a section provides vides an overview of the ViennaIPD control language, a means of structuring variables to enable associative whereas the second section outlines the programming variable definitions. A section holds an arbitrary set of interface. Furthermore, the third section depicts a use variables and subsections. case example. Finally, the fourth section compares Vi- ennaIPD to various other input control approaches.

34 INPUT FILE SPECIFICATION However, this variable type can be used to temporarily The input file specification is based on a comprehensible store data, for example the result of a computation. language. The usage is similar to common programming Sections languages, e.g. C. Additionally, object oriented features ViennaIPD supports structures of variables, so called are provided to enable structuring of large data sets, sections, to manage large input files. A section is defined i.e. inheritance mechanisms. Furthermore, a powerful with unit system is provided which supports the validity of computations based on quantities. 1

{ ... }

Variables The following snippet depicts a section named Solve An arbitrary number of variables can be defined. The with a read-only keyword variable. general definition of a variable is 1 Solve { maxStepSize = 1e30; } 1 = ; 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 1 BaseSection { 2 SubSection { is mentioned, the default key type is used. 3 SubSubSection {} can be of any length, can contain 4 } capital and small letters, an underscore, and numbers. 5 }

Description ViennaIPD enables also inheritance of sections. ext external variable - read- and writeable 1 BaseSection { x1 = −3; } key keyword variable - read-only (default) 2 DerivedSection : BaseSection; aux auxiliary variable - hidden DerivedSection is inherited from BaseSection. Con- Table 1: Types of Variables sequently, DerivedSection contains all elements (vari- ables and subsections) of BaseSection. However, the name must not begin with a number. An Note, that the variables of BaseSection transparently expression can be assigned to a variable by using the exist in DerivedSection. Hence, if a variable in assignment operator = and a valid data-type (Table 2). BaseSection changes, it changes in DerivedSection too. Type Example Furthermore, is supported.

Boolean a = true; 1 BaseSection1 { a = 1 ; } Integer a = 3; 2 BaseSection2 { b = 3 ; } Real a = 3.1415; 3 DerivedSection : BaseSection1 , BaseSection2; Complex a = 4.3 + 3.1 j; DerivedSection a b Quantity a = 3.1415 "m/s"; consists of two variables and in- BaseSection1 BaseSection2 String a = "This is a string"; herited from and , respec- Array a = [1, "pi", 3 A]; tively. Additionally, conditional inheritance enables to inherit Table 2: Types of Data from sections based on specific conditions. 1 Section : BaseSection1 ? expression1 , The following snippet depicts a few examples which 2 BaseSection1 ? expression2 , make use of the available variable types. 3 ... {}

1 s o m e f l o a t = 3 . 3 ; Conditional inheritance is an extension to multiple in- 2 key some text = ”some Text”; heritance. Several base sections can be specified for in- 3 ext x = 3 2 ; 4 ext y = 4 ; heritance, an expression can be assigned to each one. 5 aux a = s q r t ( x ∗ x + y ∗ y ) ; The following snippet depicts the usage. 6 ex = x / a ; 1 7 ey = y / a ; Switch = 0 ; 2 D e r ivedSection : BaseSection1 , 3 > Lines 1,2,6,7 depict keyword variables. Hence, the as- BaseSection2 ? (Switch −1) , 4 BaseSection3 ? (Switch < 1) signed data can be accessed only, not altered. Lines 3,4 5 {} depict external variables, for which data can be accessed and altered. Line 5 outlines an application case for the DerivedSection is always inherited from auxiliary variable. This variable cannot be accessed by BaseSection1. As Switch is 0, the conditions for the programming interface, it is hidden. BaseSection2 and BaseSection3 both hold.

35 Therefore, DerivedSection is additionally inherited 1 from BaseSection2 and BaseSection3. If Switch Q1 = 3 ”A” ; 2 Q2 = 2 ”m” ; is set to 2, DerivedSection is solely inherited from 3 Q3 = Q1 ∗ Q2 ; //OK BaseSection1 and BaseSection2. 4 Q4 = Q1 + Q2 ; // Error Elements of inherited sections can be locally modified.

1 BaseSection { PROGRAMMING INTERFACE 2 x = 1 ; The ViennaIPD Programming Interface is based on the 3 y = 2 ; 4 } C programming language. It provides an interface to the 5 DerivedSection : BaseSection { y = 4 ; } 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 Interface Setup and the variable y is locally modified. So the vari- To be able to use the interface the ViennaIPD header able DerivedSection.x equals 1 and the variable file has to be included. DerivedSection.y equals 4. 1 #include ”ipd.h” Functions The following code snippet depicts the initialization and ViennaIPD enables the use of functions within input the population of the datastructure from an input file. files. Functions can be used in expressions which are stored in variables. 1 // basic initialization 2 i p d I n i t (NULL, NULL) ; 1 < > < > < > type variable name = function (parameters ); 3 // create a new database 4 ipdCreateBase(”NameOfTheDatabase” , 0); An arbitrary number of parameters is supported. 5 // read the inputfile 6 ipdReadInputDeck(argv [1]); 1 a1 = func1(); // 0 Parameter 2 a2 = func2(1 + 2); // 1 Parameter 3 a3 = func3(”hello”, a1); // 2 Parameter Accessing Data ViennaIPD provides built-in functions, for example Specialized getter and setter functions are provided to a large set of mathematical functions, e.g. sin(), access and alter specific data types. The following code pow(), sqrt(), to list a few of them. The following snippet depicts the reading and writing process based snippet depicts the computation of the sine of a com- on these functions. plex number. 1 // declare a variable of type long 2 1 a = sin(4.42 + j ∗ 5 . 9 ); ipdLong i ; 3 // get the "c" integer value Furthermore support functions are provided, e.g. if() 4 ipdGetIntegerByName(”∼c ” , &i ) ; 5 // set the "c" integer value statement, conversion functions, array sizes, random 6 ipdSetIntegerByName(”∼c ” , 2 ) ; number generator, to name a few. Note the ∼ prefix, which indicates the root level of the Units datastructure hierarchy. Therefore variables can be ac- ViennaIPD provides a powerful unit system. A unit is cessed by absolute path addressing. For example access- used in combination with the quantity datatype (Table ing an integer variable named a within a section named 2) and consists of a valid unit name, of which many are BaseSection would be implemented by the following: provided. Quantity examples are: 1 // declare a variable of type long 1 q1 = 3 . 0 A; 2 ipdLong i ; 2 q2 = 5 . 5 ”V ∗ A” ; 3 // get the "BaseSection" member value "a" 3 q3 = 4.2 ”kg m/s s”; 4 ipdGetIntegerByName(”∼BaseSection.a”, &i );

Note that if a quantity is based on several unit names, Data can also be accessed without absolute addressing. double quotes have to be used (Lines 2,3). Unit names This approach can be utilized by setting the current can be separated by a whitespace or an asterisk * (Line section. In relation to the previous example, the current 2). The use of a single slash / indicates the beginning section can be set to BaseSection as follows: of the denominator. Hence, Line 3 represents the unit kg m/s2. Quantity based computations are checked for 1 ipdSetCSByName(”∼BaseSection”); semantically correct operations. Therefore, an error oc- Consequently, the data can be accessed directly curs, if two quantities with different units are summed up, as this would result in a mixed up physical quantity 1 // get the integer data associated with the "a" and, therefore, looses its validity. The following snippet 2 // variable in the current section 3 ipdGetIntegerByName(”a”, &i ); outlines this behavior.

36 Iterators COMPARISON ViennaIPD provides iterators for convenient traversal A comparison of different input control software pack- of datastructures. The following snippet creates a new ages is presented next. The comparison is based on the iterator on the root level following features.

1 // define a new iterator • convenient : The input language 2 i p d I t e r a t o r t ∗ iNode = NULL; 3 // set the iterator to traverse the root level should be intuitive to scientists with slight back- 4 ipdIteratorNewAtRootSection(&iNode , ipdANY); ground in programming. This results in an easy fa- miliarization which, furthermore, reduces the over- All elements, e.g. variables, sections, on the root level all implementation effort. can be traversed. • unit system: Typically scientific computing relies

1 // traverse as long as there are elements on on physical quantities. Hence, it is of major inter- 2 // the root level est to provide a computation facility which respects 3 while (ipdIteratorIsValid(iNode)) { units and therefore enables a correct setup of phys- 4 // retrieve the name of the current element ical quantities. 5 ipdConstString itemName = 6 ipdIteratorGetItemName(iNode ); • memory consumption: The memory consumption, 7 // is the element a variable? for example the peak heap memory usage, should i f 8 (ipdIteratorGetType(iNode) == ipdVARIABLE) be kept small. 9 printf(”variable: %s \n”, itemName); 10 // is the element a section? • execution performance: The input control software 11 else should not decrease the overall execution perfor- 12 i f (ipdIteratorGetType(iNode) == ipdSECTION) mance of the scientific application. 13 printf(”section: %s \n”, itemName); 14 // increment the iterator to point ViennaIPD is compared to the common scripting 15 // to the next element 16 ipdIteratorDoNext(iNode); languages, Lua [7], AngelScript [8], and Python [9] in 17 } 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 The following depicts an exemplary ViennaIPD input which extends the functionality of mature programming file which contains a small dataset. languages, like C. Lua is a minimalistic, C based library 1 E l e c t r o n s { which solely exists embedded in host applications. Lua 2 uL300 =0.143 ”mˆ2/V∗ s ” ; can be used by different programming languages, e.g. 3 uLImin300 = 0.008 ”mˆ2/V∗ s ” ; C, C++, Fortran. 4 Cref300 = 1.12e17 ”cmˆ−3” ; 5 CrefexpT = 3.2; AngelScript is a flexible cross-platform scripting library. 6 } C and C++ functions can be called within an An- 7 Holes : Electrons { gelScript environment, hence code can be reused effi- 8 uL300 =460 ”cmˆ2/V∗ s ” ; ciently. 9 uLImin300 = 45 ”cmˆ2/V∗ s ” ; 10 Cref300 = 2.23e17 ”cmˆ−3” ; Python is a mature programming language, but is also 11 } used as a scripting language. Python offers a C-API, and a C++ library for Python interoperability is also Note the different units for the same parameters in Lines available [10]. 2,3,8,9. The unit system automatically converts the All these input control languages offer interoperability units into SI units, hence, the quantities presented in with C and C++. Note, that most of the available Lines 8,9 are internally converted to: 0.046m2/s · V 2 programming languages, for example Fortran, are able and 0.0045m /s · V , respectively. Further note, that to interoperate with C. Electrons and Holes have different quantities for the In the following, benchmark results are presented and Cref300 parameter, which too get converted (Lines discussed. The test platform is a PC with an AMD 4,10). Due to inheritance, both sections use the same Phenom II X4 - 965 CPU and 8GB of RAM. The operat- value for the CrefexpT parameter (Line 5). The follow- ing system is a Gentoo Linux 64-bit with a 2.6.32 kernel. ing depicts the access of some data of the Holes section.

1 double ul , uLImin ; Table 3 depicts a comparison of the peak memory con- 2 char∗ u n i t ; sumption and the execution time of a reference applica- 3 ipdGetRealQuantityByName(”∼Holes .uL300”, tion which is driven by the introduced control languages. 4 &ul, &unit); 5 ipdGetRealQuantityByName(”∼Holes .uLImin300” , To depict the overhead of the input control languages, 6 &uLImin, &unit ); the standalone application, without any input control, is 7 std : : cout << u l << ”” << u n i t << std : : endl ; investigated too. The memory usage evaluation is based 8 << << << << std : : cout uLImin ”” u n i t std : : endl ; on Valgrind [11].

37 Peak Heap Execution [4] M. Meinel, “FlowSimulator: A Python-controlled Software Memory Time Approach to Unify Future CFD Simulation Work- [KB] [ms] flows,” in EuroSciPy 2009, 2009. No Input Control 0.8 6 [5] S. Wagner et al., “MINIMOS-NT User’s Guide,” Lua 32 18 Institute for Microelectronics, Technische Univer- AngelScript 34 162 sit¨atWien. Python 2132 627 [6] R. Klima, “Three-Dimensional Device Simulation ViennaIPD 543 32 with Minimos-NT,” Dissertation, Technische Uni- Table 3: Comparison of peak memory consumption and versit¨atWien, November 2002. execution time. [7] R. Ierusalimschy, L. H. de Figueiredo, and The following table compares the features of the intro- W. Celes, “Lua 5.1 Reference Manual.” [Online]. duced input control languages. Available: http://www.lua.org [8] “AngelScript Manual.” [Online]. Available: Software Units Mem Exec http://www.angelcode.com/angelscript/ Lua - ++ ++ [9] “Python Documentation.” [Online]. Available: AngelScript - ++ + http://www.python.org Python ++ o o ViennaIPD ++ + ++ [10] “Boost Python C++ Library.” [Online]. Available: http://www.boost.org Table 4: Feature Comparison of input control languages. [11] “Valgrind.” [Online]. Available: Feature status: ++ excellent, + good, o fulfilled, - missing http://valgrind.org/ Consequently, ViennaIPD is especially attractive for ap- [12] “Institute for Microelectronics, Technis- plications which need a robust, fast, and light-weight che Universit¨at Wien.” [Online]. Available: unit system at the input file level. http://www.iue.tuwien.ac.at CONCLUSION BIOGRAPHY A powerful control language for scientific computing has JOSEF WEINBUB received the BSc degree in elec- been introduced. The key features are trical engineering and the degree of ”Diplomingenieur“ • C-like language for input files in microelectronics from the ”Technische Universit¨at • arbitrarily nested expressions Wien“ in 2009. He is currently working on his doc- • powerful inheritance mechanisms toral degree, where his scientific interests include mod- • unit system ern programming techniques for scientific computing, • C/C++ programming interface high-performance computing, computational topology and adaptive mesh generation. The application usage has been investigated in depth. KARL RUPP received the BEng degree in electri- Furthermore, the input file specification and the pro- cal engineering from the ”Technische Universit¨atWien“ gramming interface have been discussed in detail. Input in 2006, the MSc in computational mathematics from file snippets as well as code snippets for the program- Brunel University in 2007, and the degree of ”Diplomin- ming interface have been presented to outline the usage. genieur“ in microelectronics and in technical mathemat- ViennaIPD is part of the Viennese TCAD simulation ics from the ”Technische Universit¨atWien“ in 2009. He tools which are provided by the Institute for Microelec- is currently working on his doctoral degree, where his tronics [12]. scientific interests include generative programming of discretization schemes such as the finite element method REFERENCES for the use in multiphysics problems. [1] D. Meeker, “Finite Element Method Magnetics SIEGFRIED SELBERHERR was born in Austria - User’s Manual,” 2007. [Online]. Available: in 1955. He received the degree of ”Diplomingenieur“ http://www.femm.info/wiki/HomePage in electrical engineering and the doctoral degree in tech- [2] A. Olabi and A. Grunwald, “Computation of mag- nical sciences from the ”Technische Universit¨atWien“ netic field in an actuator,” Simulation Modelling in 1978 and 1981, respectively. Dr. Selberherr has been Practice and Theory, vol. 16, no. 10, pp. 1728 – holding the ”venia docendi“ on computer-aided design 1736, 2008. since 1984. Since 1988 he has been the chair professor [3] J. Iniguez and V. Raposo, “Numerical simulation of the Institute for Microelectronics. From 1998 to 2005 of a simple low-speed model for an electrodynamic he served as dean of the Faculty for Electrical Engineer- levitation system based on a halbach magnet ar- ing and Information Technology. His current research ray,” Journal of Magnetism and Magnetic Materi- interests are modeling and simulation of problems for als, vol. 322, no. 9-12, pp. 1673 – 1676, 2010. microelectronics engineering.

38