An Efficient Method for Defining Multivariate Functions Using Expression Templates for Arrays in C++ and CUDA

Document Type : Computer Article

Author

Faculty of Engineering Science, University of Tehran, Tehran, Iran

Abstract

In this paper an efficient method for defining multi-variable functions using expression templates for array computations in computational fluid dynamics simulations in C++ is introduced. The method is implemented using variadic templates which is a new feature in C++. One of the advantages of the method is its easy of use for users of computational fields. The user can define and use his own function with any number of input arguments without having knowledge of templates programming concepts. The present method may replace conventional expression templates in developing numerical libraries. For three different functions, including arithmetic operations and trigonometric functions, the efficiency of the proposed method for arrays of different sizes is compared with that of the conventional expression templates, two different C++ syntax and Fortran language. Furthermore, the performance of the method in terms of the compilation time and executable file size is demonstrated. A similar comparison on Graphic Processing Units (GPU) using CUDA is made and the efficiency of the method is shown. The results indicate that, for any array size, the present method has a very good performance in terms of computational time, compilation time and executable file size. Finally, as an application of the proposed method, a numerical simulation is done.

Keywords


 
[[1]] https://openfoam.org.
[[2]] Jasak, H., Jemcov A., Tukovic, Z. (2007). “Openfoam: A C++ library for complex physics simulations”. International Workshop on Coupled Methods in Numerical Dynamics, IUC, Dubrovnik, Croatia, September 19-21.
[[3]] http://www.overtureframework.org.
[[4]] Henshaw, W. D. (1996). “Overture: An object-oriented system for solving PDEs in moving geometries on overlapping grids”. First AFOSR Conference on Dynamic Motion CFD.
[[5]] Bangerth, W., Hartmann, R., Kanschat, G. (2007). “deal.II – a general purpose object oriented finite element library”. ACM Transactions on Mathematical Software, Vol. 33, Issue 4. Article 24.
[[6]] Bangerth, W., Davydov, D., Heister, T., Heltai, L., Kanschat, G., Kronbichler, M., Maier, M., Turcksin, B., Wells, D. (2016). “The deal.II library, version 8.4”, Journal of Numerical Mathematics, Vol. 24, pp. 135-141.
[[7]] Blatt, M., Bastian, P. (2007). “The iterative solver template library”. Applied Parallel Computing. State of the Art in Scientific Computing, Vol. 4699 of Lecture Notes in Computer Science, Springer.
[[8]] Blatt, M., Bastian, P. (). “On the generic parallelisation of iterative solvers for the finite element method”. International Journal of Computational Science and Engineering, Vol. 4, Issue 1, pp. 56–69.
[[9]] http://www.dune-project.org.
[[10]] Logg, A., Mardal, K. A., Wells G. N., et al. (2012), “Automated Solution of Differential Equations by the Finite Element Method”. Lecture Notes in Computational Science and Engineering, Springer.
[[11]] Alnæs, M. S., Blechta, J., Hake, J., Johansson, A., Kehlet, B., Logg, A., Richardson, C., Ring, J., Rognes, M. E., Wells, G. N. (2015). “The fenics project version 1.5”, Archive of Numerical Software, Vol. 3, No. 100.
[[12]] Cantwell, C. D., Moxey, D., Comerford, A., Bolis, A., Rocco, G., Mengaldo, G., De Grazia, D., Yakovlev, S., Lombard, J. E., Ekelschot, D., Jordi, B., Xu, H., Mohamied, Y., Eskilsson, C., Nelson, B., Vos, P., Biotto, C., Kirby, R. M., Sherwin, S. J. (2015). “Nektar++: An open-source spectral/element framework”. Computer Physics Communications, Vol. 192, pp. 205–219.
[[13]] Abrahams, D., Gurtovoy, A. (2005). “C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond”. Addison-Wesley.
[[14]] http://www.nongnu.org/freepooma.
[[15]] http://www.boost.org/doc/libs/1610/libs/numeric/ublas/doc.
[[16]] http://blitz.sourceforge.net.
[17] Schildt, H. (2012). “C++ The Complete Reference”. 5th Edition, McGraw-Hill Education.
[18] Hemmat Esfe, M., Sadodin, S. (2012). “Flow Behavior and Thermal Performance of Double Lid-Driven Cavity Subjected to Nanofluid with Variable Properties”. Journal of Modeling in Engineering, Vol. 10, Issue 30, pp. 43-60.
[19] Abbasian Arani, A. A., Aghaee, A., Ehteram, H. (2013). “Numerical Investigation of Brownian Motion Effect on Nanofluid Mixed Convection on Enclosure with a Hot Central Heat Source”. Journal of Modeling in Engineering, Vol. 11. Issue 34, pp. 15-29.
[20] Sadodin, S., Hemmat Esfe, M., Noroozi, M. J. (2011). “Numerical Simulation of Mixed Convection of Fluid Flow and Heat Transfer within Car Radiator with an Inside Hot Obstacle Filled with Nanofluid”. Journal of Modeling in Engineering, Vol. 9, Issue 25, pp. 33-46.
[21] Iglberger, K., Hager, G., Treibig, J., Rde, U. (2012). “Expression templates revisited: A performance analysis of current methodologies”. SIAM Journal on Scientific Computing, Vol. 34, Issue 2, pp. C42–C69.
[22] Esfahanian, V., Mahmoodi Darian, H., Gohari, S.M.I. (2013). “Assessment of weno schemes for numerical simulation of some hyperbolic equations using gpu”. Computers and Fluids, Vol. 80, pp. 260–268.
[23] Mahmoodi Darian, H., Esfahanian, V. (2014). “Assessment of weno schemes for multi-dimensional euler equations using gpu”. International Journal for Numerical Methods in Fluids, Vol. 76, Issue 12, pp. 961–981.
[24] Hoffmann, K. A., Chiang, S. T. (2000). “Computational Fluid Dynamics”. 4th Edition, Engineering Education System.