the linked matrix methods collection for flexible sequential ... - CiteSeerX

1 downloads 0 Views 160KB Size Report
Code is thorough documented by a user's guide [7] and a reference manual for library developers ... by default the library sets it as unsigned int type. Size type.
MULTIBODY DYNAMICS 2007, ECCOMAS Thematic Conference C.L. Bottasso, P. Masarati, L. Trainelli (eds.) Milano, Italy, 25–28 June 2007

THE LINKED MATRIX METHODS COLLECTION FOR FLEXIBLE SEQUENTIAL AND PARALLEL OBJECT-ORIENTED PROGRAMMING Daniel Iglesias? and Juan J. Arribas ? ? Departamento

de Mec´anica de Medios Continuos y Teor´ıa de Estructuras Escuela de Ingenieros de Caminos, Universidad Polit´ecnica de Madrid. C/ Profesor Aranguren s/n, 28040 Madrid, Spain e-mails: [email protected], [email protected], web pages: http://w3.mecanica.upm.es/˜diglesias, http://w3.mecanica.upm.es/˜jja

Keywords: Dense, sparse, algebra, linear, nonlinear and ODE sequential and parallel solvers. Abstract. This work presents a metalibrary for numerical computations which main goal is the ability to enhance different existing methods in the same environment, with the same syntax, thus giving a full and long term solution for the computational mathematics. This is achieved by an object-oriented design in two layers that separate the features accessible to users (API) and the code that implements those for the built-in and linked types and functions. The use of different data, matrix and vector types is enhanced by an intense use of templates and the high performance of the linked libraries is ensured with very few template specialization. Also a parallel extensions module has been developed for high computing demands.

1

Daniel Iglesias and Juan J. Arribas

1

INTRODUCTION

The development and research of simulation techniques in engineering usually requires programming computer applications with high computing demands. Sparse storing, vectorization and parallelization are now common features used by these applications. There is a large amount of public domain libraries available to support the manipulation of numerical data and each of them offers many features to perform most of the operations needed for scientific computations. Prior to the application programming, a researcher must make some fundamental decisions that will condition the future development. Among these we find the programming language and support numerical libraries. Although traditionally the Fortran language has been chosen for many scientific numerical applications because of its numerical efficiency, especially when using the BLAS and LAPACK support libraries, it does not offer the advantages of flexibility and abstraction that a pure object-oriented language does. With the evolution of generic programming and its application to numerical methods and bindings to other languages, the C++ language has turned out as a true alternative to Fortran. Even large application projects in multibody simulation, such as MSC.ADAMS [2] have noticed such an advantage in code maintenance and extension that have made the transition to C++, even improving the whole application efficiency. The selection of numerical libraries include linear algebra basic operations, linear systems solvers and, frequently, nonlinear and differential systems solvers too. Once that the developing work starts, a change of the supporting math library may produce a problem by means of reprogramming and possible rearranging the structure of the program. This situation is very common and is usually motivated by a change of needs in the software application, typically because it has grown and it needs more powerful and specific methods or because the research line has evolved and requires different capabilities. When that developing state arrives, the ideal situation would require the minimum amount of modifications in the program, maximizing the reuse of the existing code. Also, when using a developed application, not all the problems that are being solved have the same characteristics so it is possible that a support library suits better than other depending of the problem run. Switching between different libraries in a user context, without the need of a recompilation of the code is a rare feature in numerical libraries available. The ability of comparing different libraries is also important when an investigation is being carried out. 2

DESCRIPTION The library’s main characteristics are the following: • The library is divided in several sections. A main include file allows linear solvers and basic algebra operations. Secondary include files add nonlinear solvers, ordinary differential systems manipulation, including explicit and implicit integrators, and parallel extensions. • The programming language used is standard C++, as described in [3] and [4]. The class templates allow different numeric types without any change in how functions are called or operators are used. • All the facilities of object oriented programming (OOP) have been deeply studied and applied from design stage reducing maintenance, support and future development efforts. This has been a key point for a straightforward extension of parallel computing capabilities. 2

Daniel Iglesias and Juan J. Arribas

• Any algebra and numerical solvers library can be linked easily and then used without changing the application’s code. Some well-known libraries, like SuperLU [5] or GMM++ [6], are already linked to the collection. • Once the application has been developed, changing the type of matrices and vectors used does not require any modification and can be implemented as a run-time option. The same works for linear and non-linear solvers. • Code is thorough documented by a user’s guide [7] and a reference manual for library developers and contributors. 2.1

Matrix and Vector classes

The template classes lmx::Matrix, lmx::DenseMatrix and lmx::Vector allow the creation of the basic objects used by LMX. Template parameter, T, can be any of the types shown in table 1. Data type Description int Integer long Long integer float Simple precision real double Double precision real std::complex Single precision complex std::complex Double precision complex cofe::TensorRank1 1st order tensors cofe::TensorRank2 2nd order tensors cofe::TensorRank2Sym Symmetric tensors Table 1: Matrix and vector value types, T

The type of data used for indexing vectors and matrices can be any of the table 2, although by default the library sets it as unsigned int type. Size type Description int Integer unsigned int Positive integer long Long integer unsigned long Positive long integer Table 2: Matrix and vector size types

All these classes can be instantiated using any of their constructors. Once an object has been created, it can be resized, filled, assigned to another object and, of course, be placed as a parameter in functions and overloaded operators. Different types of matrix and vector types can be chosen by calling their specific function, either lmx::setMatrixType(int type) or lmx::setVectorType(int type), where each type value are shown in tables 3 and 4. 3

Daniel Iglesias and Juan J. Arribas

Each linked library facilities are active only when the compiler finds a #define HAVE_NAMEOFLIBRARY in the code1 (or an equivalent define flag is set). If so, headers must be included at compile time. Also, if the linked library is implemented in an archive file, that file and its dependencies should be available at link time. While Matrix and Vector classes can switch their type, the DenseMatrix class always uses Type_dense container, independently of which type is set using the lmx::setMatrixType(int type) function. As both, setMatrixType(int) and setVectorType(int) functions can only be called once, it is not possible to mix different Vector and Matrix types during an execution. type Matrix type Description 0 Type_dense Based on std::vector< std::vector > 1 Type_csc CSC sparse using std::vector 2 Type_gmm Based on gmm::dense_matrix 3 Type_gmm_sparse Based on gmm::row_matrix< gmm::rsvector > Table 3: Matrix types

type Vector type Description 0 Type_stdvector Based on std::vector 1 Type_gmm_sparse1 Based on gmm::wsvector Table 4: Vector types

2.2

Linear algebra operations

A full set of common operations is available for the Matrix, DenseMatrix and Vector classes. Compatibility between any Matrix type and the DenseMatrix is ensured for all the operations. The operations set can be classified in two parts, by means of efficiency: • Overloaded operators allow a clear syntax and a fast development of the code. • Specialized functions increase efficiency, specially when compared to the equivalent const operators (+, -, *). A brief summary of main algebra operations is shown in table 5. There are also available other support functions that implement miscellaneous methods for resizing, streaming, file storing with standard formats, automatic filling, etc. 2.3

Linear solvers

There are two ways for solving a system: • solveLinear(Matrix, Vector, Vector) is a driver routine that, depending on Matrix characteristics, tries to call the most adequate solver. 1

At this time, valid flags are HAVE GMM, HAVE SUPERLU and HAVE LAPACK

4

Daniel Iglesias and Juan J. Arribas

Matrix and Vector algorithms A, B, C are Matrix, DenseMatrix or Vectors of correct dimensions and k is a data type Function Operation A.add(B,C) A ←− B + C A.subs(B,C) A ←− B − C A.mult(B,C) A ←− B × C A.multElem(B) A ←− A ⊗ B A.multElem(B,C) A ←− B ⊗ C A=B A ←− B A+=B A ←− A + B A-=B A ←− A − B A*=k A ←− kA A=B+C A ←− T emp ←− B + C A=B-C A ←− T emp ←− B − C A=B*C A ←− T emp ←− B ∗ C A=B*k A ←− T emp ←− B ∗ k A=k*B A ←− T emp ←− k ∗ B Matrix only algorithms A, B, C are Matrix or DenseMatrix Function Operation A.transpose() A ←− AT A=transposed(B) A ←− T emp ←− B T Vector only algorithms x is a Vector and k, temp are data types Function Operation P k = x.norm1() k ←− temp ←− q i |xi | P 2 k = x.norm2() k ←− temp ←− i xi Table 5: Algebra operations

• LinearSystem class offers much more control over the solver and options selected. The different solvers available (shown in table 6) are switched using the function setLinSolverType(int). Depending on Matrix and linear solver types selected, the combinations shown in table 7 are possible. When a solver is not available, an error is thrown. Lapack’s ?posv or ?gesv linear solver driver routines are used instead of built-in Gauss elimination procedure if HAVE_LAPACK is defined. 2.4

Nonlinear solvers

The structure of the NLSolver class is prepared to implement multiple solvers. Although at this time only the Newton-Rhapson Method is working, there are plans to also introduce quasi-Newton methods such as the Broyden-Fletcher-Goldfarb-Shanno (BFGS) method. As external functions are needed for the solver to compute the residue and jacobian of the system, the API of this class has some set functions that allow the interfacing of any func5

Daniel Iglesias and Juan J. Arribas

lin solver type Description 0 Direct for symmetric matrices 1 Direct for non-symmetric matrices 2 Iterative for symmetric matrices 3 Iterative for non-symmetric matrices Table 6: Linear solvers types.

lin solver type matrix type Solver used: 0 0 Gauss or ?posv 0 1 SuperLU 0 2 gmm::lu solve 0 3 gmm::lu solve 1 0 Gauss or ?gesv 1 1 SuperLU 1 2 gmm::lu solve 1 3 gmm::lu solve 2 0 lmx::Cg 2 1 lmx::Cg 2 2 lmx::Cg 2 3 lmx::Cg 3 0 3 1 3 2 3 3 gmm::gmres Table 7: Linear solvers used for each Matrix type.

tion placed in another class just as long as the arguments are the same as those shown in its declaration. The sample code next shows how to use the nonlinear solver class to solve a system declared and implemented outside the library. First, MyExternalSystem class is declared. Afterwards, in the main function, an object of that class is solved using the LMX nonlinear solver. class MyExternalSystem{ public: MyExternalSystem(){} ˜MyExternalSystem(){} void myResidue(lmx::Vector& res_in, lmx::Vector& q_in); void myJacobian(lmx::Matrix& jac_in, lmx::Vector& q_in); bool myConvergence( lmx::Vector& res_in );

6

Daniel Iglesias and Juan J. Arribas

private: ... }; int main(int argc, char* argv){ lmx::setMatrixType(0); lmx::setVectorType(0); lmx::setLinSolverType(0); lmx::Vector b(3); b.fillIdentity(); MyExternalSystem theSystem; lmx::NLSolver theSolver( b ); theSolver.setSystem( theSystem ); theSolver.setResidue( &MyExternalSystem::myResidue ); theSolver.setJacobian( &MyExternalSystem::myJacobian ); theSolver.setConvergence( &MyExternalSystem::myConvergence ); theSolver.setMaxIterations( 10 ); theSolver.solve(); cout 0.002468 0.011276 Table 11: Read and write comparison between STL and LMX classes and pointer arrays

Library version: LMX-1.0.pre13. Linked libraries: gmm-2.0, SuperLU-3.0, BLAS-3.0.958, LAPACK-3.0.958. 5

APPLICATIONS

Although the library can be used in a wide range of applications, the design was focused on the support for the development of mechanical engineering programs within the Departmento de Mec´anica de Medios Continuos y Teor´ıa de Estructuras at the Universidad Polit´ecnica de Madrid, Spain. The library has been successfully used in the development of several simulation programs, ranging from a frame structures application to a meshfree solution for static and dynamic analysis of solids [13]. At this time, the solver module of the multibody package EPI [14] is being redesigned to adopt LMX as its support library. Currently the code features static and dynamic analisys of systems composed of 3D rigid bodies, trusses, membranes, solid FE with large displacements and strains, hiperelastic materials, nonlinear springs and dampers, joints, clearances and other constraints. The new version of the code will have new capabilities in representing the dynamics of flexible bodies with different formulations, including also contacts. 6

ACKNOWLEDGEMENTS

Both authors want to acknowledge the support by the Ministerio de Educaci´on y Ciencia from the Government of Spain with the project DPI2006-15613-C03-02 entitled “Modelizaci´on num´erica eficiente de grandes sistemas flexibles con aplicaciones de impacto” We are also want to express our gratitude to Roberto Ortega Aguilera for his collaboration in the development of the code and Juan Carlos Garc´ıa Orden for his contributions in the library’s design. REFERENCES [1] E. Anderson, Z. Bai, C. Bischoff, J. Demmel, J. Dongarra, J. DuCroz, A. Greenbaum, S. Hammarling, A. McKenney, and D. Sorensen. LAPACK: A portable linear algebra package for high-perfomance computers. Proceedings of Supercomputing ’90 pages 1-10. IEEE press, 1990. [2] G. Ottarsson, T. McDevitt, J. Ortiz, M. Belczynski and D. Negrut. The ADAMS C++ class library: Extensability through object oriented programming. Sixth U.S. National Congress on Computational Mechanics, 2001, Dearborn, MI.

12

Daniel Iglesias and Juan J. Arribas

[3] B. Stroustrup. The C++ Programming Language. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 2000. [4] D. Kalev and J. Schmuller. The ANSI/ISO C++ Professional Programmer’s Handbook. Que Corp., Indianapolis, IN, 1999. [5] James W. Demmel, John R. Gilbert, Xiaoye S. Li. SuperLU user’s guide. 2003. . [6] Yves Renard, Julien Pommier. The Linked Matrix Methods Collection User’s Guide. INSA, Toulouse, 2007. . [7] D. Iglesias. The Linked Matrix Methods Collection User’s Guide. Departamento de Mec´anica de Medios Continuos y Teor´ıa de Estructuras, 2006. . [8] Marc Snir, Steve Otto, Steven Huss-Lederman, David Walker, Jack Dongarra. MPI The Complete Reference The MIT Press, 1998. . [9] C. W. Gear. Numerical Initial Value Problems in Ordinary Differential Equations. Edgewood Cliffs, 1971. [10] E. Fehlberg. Low order classical Runge-Kutta formulae with stepsize control and their application to some heat transfer problems. NASA Technical Report, R-315, 1969. [11] H. Hilber, T. Hughes, R. Taylor. Improved Numerical Dissipation for Time Integration Algorithms in Structural Dynamics. Earthquake Engin. and Struct. Dynamics, 5, 283-292, 1977. [12] J. C. Simo, N. Tarnow. The Discrete Energy-Momentum Method: Conserving algorithms for nonlinear elastodynamics. Z. Angew. Math. Phys., 43, 757-793, 1992. [13] D. Iglesias. Pancho - A meshfree simulation tool for solid body mechanics. Departamento de Mec´anica de Medios Continuos y Teor´ıa de Estructuras, 2006. . [14] J. C. Garc´ıa Orden. EPI: Gua del Usuario. Departamento de Mec´anica de Medios Continuos y Teor´ıa de Estructuras, 2006. .

13

Suggest Documents