Linear matrix solving method and system based on SW heterogeneous many-core processor
By converting OpenFOAM's study grid information into a suitable matrix format on the Shenwei heterogeneous multi-core processor, and using a third-party mathematical library to solve the problem of low linear solution performance, the problem of low linear solution performance is achieved Efficient matrix solution performance improvement.
Patent Information
- Application Number
- CN202411145290.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-11-05
AI Technical Summary
When using OpenFOAM on Shenwei heterogeneous multi-core processors, the linear solver cannot quickly utilize multi-core acceleration, resulting in low solution performance.
By reading the study grid information of the computational fluid mechanics software, converting it into a preset format and generating a matrix discretely, using a third-party mathematical library such as xMath to solve linear equation systems, combining the scheduling strategies of the master and slave kernels to realize the matrix quick solution.
It effectively improves the linear solution performance of OpenFOAM on Shenwei heterogeneous multi-core processors, solves the problem that linear solvers cannot use multi-core acceleration quickly, and has good portability and high availability.
Smart Images

Figure CN118897941A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of linear matrix solution acceleration, and in particular, relates to a linear matrix solution method and system based on a Shenwei heterogeneous multi-core processor. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] OpenFOAM is an object-oriented CFD software written in C++, which has a wide range of functions to solve any problem from complex fluid flows involving chemical reactions, turbulence and heat transfer to acoustics, solid mechanics and electromagnetics. OpenFOAM uses the finite volume method to solve various partial differential equation systems and 3D unstructured polyhedral grids, using a regional decomposition parallel algorithm.
[0004] The performance of the linear solver in OpenFOAM has always been a hot topic of concern. Studies have shown that the most computationally intensive part of the example execution process is the solution of the linear equations, which accounts for about 80% of the entire program execution time. Also, because OpenFOAM has a parallel computing framework with rich interfaces and good scalability, more and more researchers are conducting various secondary developments based on OpenFOAM for performance optimization, such as the integrated optimization development of the PETSc mathematical library based on general-purpose processors and OpenFOAM, and the integrated optimization development of the AmgX mathematical library based on NV ID IA GPU heterogeneous processors and OpenFOAM. With the continuous development of domestic chips, more and more people are using OpenFOAM on machines equipped with domestic processors. The inventor found that when running OpenFOAM on the Shenwei heterogeneous multi-core processor, its linear solver could not quickly use the multi-core acceleration, resulting in low performance. Summary of the invention
[0005] The embodiment of the present invention provides a linear matrix solving method and system based on the Shenwei heterogeneous many-core processor to solve the problem of low solving performance caused by the inability of the linear solver to quickly use the many-core acceleration when running OpenFOAM on the Shenwei heterogeneous many-core processor.
[0006] According to a first aspect of an embodiment of the present invention, a linear matrix solving method based on a Shenwei heterogeneous multi-core processor is provided, comprising:
[0007] Reading in the example grid information of the computational fluid dynamics software; wherein the reading in of the example grid information is performed on the main core of the Shenwei heterogeneous multi-core processor;
[0008] Converting the control equation obtained based on the example grid information into a preset format, and discretizing each operator in the control equation to generate a first storage format matrix;
[0009] Convert the first storage format matrix into a matrix storage format in a third-party math library to obtain a second storage format matrix;
[0010] Based on the obtained second storage format matrix, a linear equation solver in a third-party mathematical library is used to solve a linear equation system; wherein the solution of the linear equation system is performed on a slave core of the Shenwei heterogeneous multi-core processor;
[0011] The solved matrix is converted into a first storage format matrix to obtain a solution result of the linear matrix, wherein the conversion is performed on the main core of the Shenwei heterogeneous multi-core processor.
[0012] Furthermore, the control equation obtained based on the example grid information is converted into a preset format, and each operator in the control equation is discretized to generate a first storage format matrix, specifically: the control equation is converted into an OpenFOAM format, and each operator is discretized by a finite volume method to generate a matrix in an LDU storage format.
[0013] Furthermore, the first storage format matrix is converted into the matrix storage format in the third-party mathematical library to obtain the second storage format matrix, specifically: all LDU storage format matrices are integrated into a linear equation system in the main core, and the linear equation system is converted into the matrix storage format in the third-party mathematical library.
[0014] Furthermore, the third-party math library adopts the xMath math library, and the second storage format matrix adopts a CSR storage format matrix.
[0015] Furthermore, based on the obtained second storage format matrix, the linear equation solver in the third-party mathematical library is used to solve the linear equation system, specifically: the second storage format matrix is read into the slave core of the Shenwei heterogeneous multi-core processor, and the linear equation solver in the xMath mathematical library is called to solve the linear equation system in the CSR storage format.
[0016] Furthermore, the solved matrix is converted into a first storage format matrix to obtain a solution result of the linear matrix, specifically: the solved CSR storage format matrix is returned to the main core, and the CSR storage format matrix is converted into an LDU storage format matrix in the main core.
[0017] According to a second aspect of an embodiment of the present invention, a linear matrix solving system based on a Shenwei heterogeneous multi-core processor is provided, comprising:
[0018] A data reading unit, which is used to read the example grid information of the computational fluid dynamics software; wherein the reading of the example grid information is performed on the main core of the Shenwei heterogeneous multi-core processor;
[0019] A format conversion unit, which is used to convert the control equation obtained based on the example grid information into a preset format, and discretize each operator in the control equation to generate a first storage format matrix; convert the first storage format matrix into a matrix storage format in a third-party mathematical library to obtain a second storage format matrix;
[0020] A solving unit, which is used to solve a linear equation system based on the obtained second storage format matrix using a linear equation solver in a third-party mathematical library; wherein the solution of the linear equation system is performed on a slave core of the Shenwei heterogeneous multi-core processor;
[0021] The solved matrix is converted into a first storage format matrix to obtain a solution result of the linear matrix, wherein the conversion is performed on the main core of the Shenwei heterogeneous multi-core processor.
[0022] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, comprising a memory, a processor and a computer program stored and running on the memory, wherein when the processor executes the program, a linear matrix solving method based on the Shenwei heterogeneous multi-core processor is implemented.
[0023] According to a fourth aspect of an embodiment of the present invention, a non-transitory computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the linear matrix solving method based on the Shenwei heterogeneous multi-core processor is implemented.
[0024] According to a fifth aspect of an embodiment of the present invention, a computer program product is provided, wherein the computer program product comprises a computer program, and when the computer program is executed by a processor, a linear matrix solving method based on a Shenwei heterogeneous multi-core processor is implemented.
[0025] One or more of the above technical solutions have the following beneficial effects:
[0026] (1) The present invention provides a linear matrix solving method and system based on the Shenwei heterogeneous many-core processor. The scheme discretizes the operators in the control equation and integrates them into a linear equation system, and solves the system with the help of a linear equation solver in a third-party mathematical library. At the same time, combined with the scheduling strategy on the master core and slave core of the Shenwei heterogeneous many-core processor, the problem of low solving performance caused by the inability of the linear solver to quickly use the multi-core acceleration when running OpenFOAM on the domestic Shenwei heterogeneous many-core processor is effectively solved.
[0027] (2) The solution of the present invention is separated from the source code of the computational fluid dynamics software and provided separately. It can be used on different versions of the computational fluid dynamics software and has good portability and high availability.
[0028] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0030] Figure 1 This is a schematic diagram of converting the LDU matrix storage format to the CSR matrix storage format described in an embodiment of the present invention;
[0031] Figure 2 It is a schematic diagram of the xMath database usage process described in an embodiment of the present invention;
[0032] Figure 3 A basic flow chart of a linear matrix solving method based on the Shenwei heterogeneous multi-core processor described in an embodiment of the present invention;
[0033] Figure 4 It is a schematic diagram of the overall flow of a linear matrix solving method based on the Shenwei heterogeneous multi-core processor described in an embodiment of the present invention. DETAILED DESCRIPTION
[0034] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0035] It should be noted that the terms used herein are for describing specific embodiments only and are not intended to be limiting of exemplary embodiments according to the present invention.
[0036] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0037] Terminology explanation:
[0038] CFD: Computational Fluid Dynamics.
[0039] PETSc: is a portable, extensible scientific computing toolkit for scalable (parallel) solutions to scientific applications for partial differential equation (PDE) modeling.
[0040] AmgX: is a GPU-accelerated core solver library that accelerates the computationally intensive linear solver parts of the simulation.
[0041] GPU: Graphics processor produced by NVID IA, also known as graphics card.
[0042] xMath: It is a high-performance extended mathematics library for domestic Shenwei heterogeneous multi-core processors.
[0043] like Figure 4 As shown, the purpose of this embodiment is to provide a linear matrix solving method based on the Shenwei heterogeneous multi-core processor, including the following processing procedures:
[0044] Step 1: Read in the example grid information of the computational fluid dynamics software; wherein the reading of the example grid information is performed on the main core of the Shenwei heterogeneous multi-core processor;
[0045] Step 2: Convert the control equation obtained based on the example grid information into a preset format, and discretize each operator in the control equation to generate a first storage format matrix;
[0046] In a specific implementation, the control equation obtained based on the example grid information is converted into a preset format, and each operator in the control equation is discretized to generate a first storage format matrix, specifically: the control equation is converted into an OpenFOAM format, and each operator is discretized by a finite volume method to generate a matrix in an LDU storage format.
[0047] Specifically, the mesh information of the OpenFOAM example is read on the main core of the Shenwei heterogeneous multi-core processor, the mathematical control equations are converted into the OpenFOAM format, each operator is discretized through the finite volume method (FVM), and then a l duMatrix (the matrix format used in OpenFOAM - LDU matrix format) is generated.
[0048] Step 3: Convert the first storage format matrix into a matrix storage format in a third-party mathematical library to obtain a second storage format matrix;
[0049] In a specific implementation, the first storage format matrix is converted into a matrix storage format in a third-party mathematical library to obtain a second storage format matrix, specifically: all LDU storage format matrices are integrated into a linear equation system in the main core, and the linear equation system is converted into a matrix storage format in the third-party mathematical library.
[0050] In a specific implementation, the third-party math library adopts the xMath math library, and the second storage format matrix adopts a CSR storage format matrix.
[0051] Specifically, in the main kernel, all l duMatrixes are integrated into a final linear equation system, and the equation system is converted to the CSR matrix storage format. Since OpenFOAM uses the LDU matrix storage format, and the xMath math library uses the more common CSR matrix storage format, it is necessary to convert the LDU matrix storage format to the CSR matrix storage format before calling the xMath math library. Figure 1 shown.
[0052] Step 4: Based on the obtained second storage format matrix, use a linear equation solver in a third-party mathematical library to solve the linear equation system; wherein the solution of the linear equation system is performed on the slave core of the Shenwei heterogeneous multi-core processor;
[0053] like Figure 3 As shown, the basic processing process from step 2 to step 4 is shown.
[0054] In the specific implementation, based on the obtained second storage format matrix, the linear equation solver in the third-party mathematical library is used to solve the linear equation system, specifically: the second storage format matrix is read into the slave core of the Shenwei heterogeneous multi-core processor, and the linear equation solver in the xMath mathematical library is called to solve the linear equation system in the CSR storage format.
[0055] Specifically, the matrix data converted into the CSR storage format is read into the slave core of the Shenwei heterogeneous multi-core processor, and the linear equation solver in the xMath mathematical library is called to solve the linear equations in the CSR storage format. The xMath mathematical library usage process is as follows: Figure 2 .
[0056] Step 5: Convert the solved matrix into a first storage format matrix to obtain a solution result of the linear matrix, wherein the conversion is performed on the main core of the Shenwei heterogeneous multi-core processor.
[0057] In a specific implementation, the solved matrix is converted into a first storage format matrix to obtain a solution result of the linear matrix, specifically: the solved CSR storage format matrix is returned to the main core, and the CSR storage format matrix is converted into an LDU storage format matrix in the main core.
[0058] Specifically, the solved matrix is first transferred from the many cores back to the main core, and the CSR matrix storage format is converted into the LDU matrix storage format in the main core; OpenFOAM uses the solved and converted LDU matrix in the main core to continue running the next time step. If it is the last time step, the final calculation result is interpreted and output.
[0059] In one or more embodiments, a linear matrix solving system based on a Shenwei heterogeneous multi-core processor is provided corresponding to the above method, including:
[0060] A data reading unit, which is used to read the example grid information of the computational fluid dynamics software; wherein the reading of the example grid information is performed on the main core of the Shenwei heterogeneous multi-core processor;
[0061] A format conversion unit, which is used to convert the control equation obtained based on the example grid information into a preset format, and discretize each operator in the control equation to generate a first storage format matrix; convert the first storage format matrix into a matrix storage format in a third-party mathematical library to obtain a second storage format matrix;
[0062] A solving unit, which is used to solve a linear equation system based on the obtained second storage format matrix using a linear equation solver in a third-party mathematical library; wherein the solution of the linear equation system is performed on a slave core of the Shenwei heterogeneous multi-core processor;
[0063] The solved matrix is converted into a first storage format matrix to obtain a solution result of the linear matrix, wherein the conversion is performed on the main core of the Shenwei heterogeneous multi-core processor.
[0064] It should be noted here that each module in this embodiment corresponds to each step in Example 1 one by one, and the specific implementation process is the same, which will not be repeated here.
[0065] In one or more embodiments, the third-party math library may also use other linear equations math libraries suitable for accelerated solution by Shenwei heterogeneous multi-core processors to replace the xMath math library, such as: swb l as math library, sw lapack math library.
[0066] In one or more embodiments, the original OpenFOAM solver can also be optimized and accelerated on the Shenwei heterogeneous multi-core processor and decoupled from OpenFOAM as an external solver.
[0067] In further embodiments, there is also provided:
[0068] An electronic device includes a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method described in Embodiment 1 is performed. For the sake of brevity, no further description is given here.
[0069] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0070] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.
[0071] A computer-readable storage medium is used to store computer instructions. When the computer instructions are executed by a processor, the method described in embodiment 1 is completed.
[0072] A computer program product, comprising a computer program, which, when executed by a processor, implements a linear matrix solving method based on a Shenwei heterogeneous multi-core processor.
[0073] The method in the first embodiment can be directly embodied as a hardware processor, or a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.
[0074] Those skilled in the art will appreciate that the units, i.e., algorithm steps, of the various examples described in the present embodiment can be implemented in electronic hardware or in a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0075] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A linear matrix solving method based on Shenwei heterogeneous multi-core processor, characterized in that: include: Reading in the example grid information of the computational fluid dynamics software; wherein the reading in of the example grid information is performed on the main core of the Shenwei heterogeneous multi-core processor; Converting the control equation obtained based on the example grid information into a preset format, and discretizing each operator in the control equation to generate a first storage format matrix; Convert the first storage format matrix into a matrix storage format in a third-party math library to obtain a second storage format matrix; Based on the obtained second storage format matrix, a linear equation solver in a third-party mathematical library is used to solve a linear equation system; wherein the solution of the linear equation system is performed on a slave core of the Shenwei heterogeneous multi-core processor; The solved matrix is converted into a first storage format matrix to obtain a solution result of the linear matrix, wherein the conversion is performed on the main core of the Shenwei heterogeneous multi-core processor.
2. A linear matrix solving method based on Shenwei heterogeneous multi-core processor as claimed in claim 1, characterized in that: The control equation obtained based on the example grid information is converted into a preset format, and each operator in the control equation is discretized to generate a first storage format matrix, specifically: the control equation is converted into an OpenFOAM format, and each operator is discretized by a finite volume method to generate a matrix in an LDU storage format.
3. A linear matrix solving method based on Shenwei heterogeneous multi-core processor as claimed in claim 1, characterized in that: The method of converting the matrix in the first storage format into the matrix storage format in the third-party mathematical library to obtain the matrix in the second storage format is specifically as follows: integrating all matrices in the LDU storage format into a linear equation system in the main core, and converting the linear equation system into the matrix storage format in the third-party mathematical library.
4. A linear matrix solving method based on Shenwei heterogeneous multi-core processor as claimed in claim 1, characterized in that: The third-party math library adopts the xMath math library, and the second storage format matrix adopts a matrix in a CSR storage format.
5. A linear matrix solving method based on Shenwei heterogeneous multi-core processor as claimed in claim 1, characterized in that: Based on the obtained second storage format matrix, the linear equation solver in the third-party mathematical library is used to solve the linear equation system. Specifically, the second storage format matrix is read into the slave core of the Shenwei heterogeneous multi-core processor, and the linear equation solver in the xMath mathematical library is called to solve the linear equation system in the CSR storage format.
6. A linear matrix solving method based on Shenwei heterogeneous multi-core processor as claimed in claim 1, characterized in that: The method converts the solved matrix into a first storage format matrix to obtain a solution result of the linear matrix, specifically: transmitting the solved CSR storage format matrix back to the main core, and converting the CSR storage format matrix into an LDU storage format matrix in the main core.
7. A linear matrix solving system based on Shenwei heterogeneous multi-core processor, characterized in that: include: A data reading unit, which is used to read the example grid information of the computational fluid dynamics software; wherein the reading of the example grid information is performed on the main core of the Shenwei heterogeneous multi-core processor; A format conversion unit, which is used to convert the control equation obtained based on the example grid information into a preset format, and discretize each operator in the control equation to generate a first storage format matrix; convert the first storage format matrix into a matrix storage format in a third-party mathematical library to obtain a second storage format matrix; A solving unit, which is used to solve a linear equation system based on the obtained second storage format matrix using a linear equation solver in a third-party mathematical library; wherein the solution of the linear equation system is performed on a slave core of the Shenwei heterogeneous multi-core processor; The solved matrix is converted into a first storage format matrix to obtain a solution result of the linear matrix, wherein the conversion is performed on the main core of the Shenwei heterogeneous multi-core processor.
8. An electronic device comprising a memory, a processor and a computer program stored and running on the memory, characterized in that: When the processor executes the program, it implements a linear matrix solving method based on the Shenwei heterogeneous multi-core processor as described in any one of claims 1-6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, a linear matrix solving method based on a Shenwei heterogeneous multi-core processor as described in any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that: When the computer program is executed by a processor, a linear matrix solving method based on a Shenwei heterogeneous multi-core processor as described in any one of claims 1 to 6 is implemented.
