Automatic recursive mesh refinement method and apparatus for unstructured grid domain specific language
By automatically constructing a recursive partitioning and data conflict resolution scheme for unstructured meshes at the DSL level, the performance and convergence issues of unstructured meshes on multi-core CPU platforms are solved, achieving efficient parallel execution and low-cost development and maintenance, and improving application portability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NAT UNIV OF DEFENSE TECH
- Filing Date
- 2026-02-11
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies struggle to balance performance, locality, and convergence on multi-core CPU platforms when dealing with data conflicts in unstructured grids. Furthermore, recursive partitioning methods suffer from high portability and development/maintenance costs, and existing programming frameworks lack the ability to automatically update recursive partitioning and mapping relationships.
This paper provides an automatic recursive partitioning method and apparatus for unstructured mesh domain-specific languages. It describes the mesh topology and indirect access patterns in a unified manner at the DSL level, automatically constructs a conflict-resolving task dependency structure, and generates conflict-free parallel target code by combining global renumbering and data rearrangement mechanisms.
It improves the parallel efficiency and data locality of unstructured grid applications on multi-core CPU platforms, reduces development and maintenance costs, and enhances performance portability. It significantly reduces implementation and maintenance costs and improves performance acceleration and numerical convergence.
Smart Images

Figure CN122111665A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer technology and relates to an automatic recursive partitioning method and apparatus for a domain-specific language for unstructured meshes. Background Technology
[0002] Unstructured meshes, due to their advantages such as strong geometric adaptability, ease of handling complex boundaries, and local refinement, are widely used in numerical computation fields such as computational fluid dynamics, computational structural mechanics, and electromagnetic simulation. These numerical computation applications are typically based on numerical discretization methods such as the finite volume method and the finite element method, updating physical quantities multiple times by traversing mesh entities such as elements, faces / edges, and nodes. Unlike regular structured meshes, the topological relationships of unstructured meshes are maintained through general graph structures and index mappings, and the computation process heavily relies on indirect addressing modes such as face-to-cell (F2C) and cell-to-node (C2N). On multi-core CPU platforms with shared memory, directly executing these computations involving indirect access in parallel can easily lead to data races and write conflicts caused by different threads simultaneously reading and writing the same data, affecting the correctness of the results and numerical convergence.
[0003] To address the aforementioned data conflict problem, existing technologies mainly employ two approaches: one at the programming model level uses explicit synchronization mechanisms such as locks and atomic operations to sequentially update shared data, thereby ensuring correctness. However, this introduces significant synchronization and cache coherence overhead on multi-core CPU platforms, hindering the full realization of multi-core parallel performance. The other approach avoids conflicts at the algorithm and scheduling level, for example, by using mesh coloring to divide potentially conflicting iterations into different "color" sets, with parallel execution within the same color and sequential progression between colors to avoid write conflicts. However, mesh coloring often disrupts the original data locality and update order, increases memory access overhead, and may lead to a decrease in the convergence speed of the iterative solver.
[0004] To reduce the burden on programmers and improve cross-platform portability, academia has proposed various portable parallel programming tools and Domain Specific Languages (DSLs). Among them, the existing implementation closest to this invention is the OP2 framework (here referred to as OP2-base) based on unstructured mesh DSLs. OP2 abstracts mesh entities and their topological relationships through sets (op_set), maps (op_map), and data objects (op_dat). Users use op_par_loop to describe the computational logic on a set, and the framework automatically generates parallel code for different hardware backends such as multi-core CPUs and GPUs based on these high-level semantics. For multi-core CPUs with shared memory, the code generation module of the OP2-base backend mainly uses a "conflict graph analysis + mesh coloring" approach to handle write conflicts caused by indirect access. It assigns iterations that may write to the same data location to different colors and executes them in batches according to color, supplemented by atomic operations when necessary, thereby achieving conflict avoidance within the DSL framework.
[0005] Existing data conflict handling and parallelization techniques for unstructured grid applications share the following common problems: (1) Traditional conflict resolution methods are difficult to balance performance, locality and convergence. Traditional methods such as explicit synchronization and mesh coloring either introduce large synchronization overhead or destroy data locality or update order, which may lead to the degradation of convergence behavior of iterative solvers. It is difficult to obtain high performance and stable numerical convergence characteristics at the same time in practical engineering applications.
[0006] (2) The software development is complex and the maintenance cost is high. Most existing recursive partitioning schemes are embedded in specific applications by manual coding. Under the current technology system, if application developers want to introduce mechanisms such as recursive partitioning, global renumbering and mapping relationship maintenance into their applications, they need to write a considerable amount of complex infrastructure code, involving a large amount of standardized engineering code such as mesh partitioning, isolation zone construction, global renumbering and mapping update. The code is large in scale, has high maintenance cost and is prone to errors.
[0007] (3) Portability limitations of recursive partitioning methods. Recursive partitioning methods are tightly coupled with specific solvers and hardware platforms. When migrating to different architectures, they often require redesign or significant modifications, resulting in poor performance portability.
[0008] (4) Deficiencies of existing programming frameworks in the ability to automatically generate code for recursive decomposition. General mathematical libraries, guidance statement models and portable parallel frameworks mainly focus on operator-level or loop-level parallel optimization, and lack the ability to directly express the unstructured mesh abstraction of "node / edge / cell + mapping". Although unstructured mesh DSL frameworks such as OP2 can automatically analyze dependencies and generate multiple backend code based on the "set + mapping" abstraction, their existing CPU backends mainly rely on traditional solutions such as coloring and atomic operations for conflict handling, and have not yet provided system capabilities such as automatic construction of recursive decomposition trees, mesh renumbering and synchronous updating of mapping relationships. Summary of the Invention
[0009] To address the aforementioned issues, this invention provides an automated recursive partitioning and data conflict resolution software architecture for shared-memory multi-core CPU platforms within the framework of a domain-specific language for unstructured grids and its converter. By uniformly describing the grid topology and indirect access patterns at the DSL level, it automatically constructs a task-dependent structure for conflict resolution. Combined with global renumbering and grid data rearrangement mechanisms, it improves the parallel efficiency, data locality, and performance portability of unstructured grid applications on multi-core CPU platforms while ensuring numerical correctness, and reduces application development and maintenance costs.
[0010] To achieve the above objectives, the embodiments of the present invention adopt the following technical solutions: On the one hand, an automatic recursive partitioning method for a domain-specific language for unstructured meshes is provided, the method comprising the following steps: Step 1: The user obtains the unstructured mesh and parallel operation parameters, and inserts or calls the conflict handling primitive interface in the front-end computation code.
[0011] Step 2: The program analysis module of the DSL converter performs syntax parsing on the source code of the target computing core, constructs an initial abstract syntax tree, and generates and standardizes code slices based on control flow and data flow analysis.
[0012] Step 3: The candidate list generation module of the DSL converter constructs a structured candidate element list based on the initial abstract syntax tree, and the abstract syntax tree construction module of the DSL converter constructs a domain-specific abstract syntax tree based on the candidate element list.
[0013] Step 4: The backend code generation module of the DSL converter generates conflict-free parallel target code based on the candidate element list and the domain-specific abstract syntax tree.
[0014] Step 5: The recursive partitioning module of the ARPT runtime library constructs an automatic recursive partitioning tree based on the grid topology data.
[0015] Step 6: The ARPT runtime library's grid data rearrangement module performs global renumbering and grid data rearrangement based on an automatic recursive partitioning tree.
[0016] Step 7: Runtime scheduling and execution of the task scheduling module of the ARPT runtime library.
[0017] On the other hand, an automatic recursive partitioning device for a domain-specific language for unstructured grids is also provided. The device includes an input module, a DSL converter, and an ARPT runtime library module. The DSL converter includes a program analysis module, a candidate list generation module, an abstract syntax tree construction module, and a backend code generation module. The ARPT runtime library module includes a recursive partitioning module, a grid data rearrangement module, and a task scheduling module.
[0018] The input module is used to obtain unstructured mesh and parallel operation parameters, and to insert or call conflict handling primitive interfaces in the front-end computation code.
[0019] The DSL converter is used to perform syntax parsing on the source code of the target computing kernel through the program analysis module, construct an initial abstract syntax tree, and generate and standardize code slices based on control flow and data flow analysis; the candidate list generation module constructs a structured candidate element list based on the initial abstract syntax tree; the abstract syntax tree construction module constructs a domain-specific abstract syntax tree based on the candidate element list; and the backend code generation module generates conflict-free parallel target code based on the candidate element list and the domain-specific abstract syntax tree.
[0020] The ARPT runtime library module is used to construct an automatic recursive subdivision tree based on grid topology data through the recursive subdivision module; to perform global renumbering and grid data rearrangement based on the automatic recursive subdivision tree through the grid data rearrangement module; and to schedule and execute tasks at runtime through the task scheduling module.
[0021] One of the above technical solutions has the following advantages and beneficial effects: The aforementioned automatic recursive partitioning method and apparatus for unstructured grid domain-specific languages propose an automated recursive partitioning and data conflict resolution software architecture for shared-memory multi-core CPU platforms within the framework of unstructured grid domain-specific languages and their converters. By uniformly describing the grid topology and indirect access patterns at the DSL level, it automatically constructs the task dependency structure for conflict resolution. Combined with global renumbering and data rearrangement mechanisms, it improves the parallel efficiency, data locality, and performance portability of unstructured grid applications on multi-core CPU platforms while ensuring numerical correctness, and reduces application development and maintenance costs. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of this application or the conventional technology, the drawings used in the description of the embodiments or the conventional technology will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 This is a flowchart illustrating an automatic recursive partitioning method for a domain-specific language for unstructured meshes in one embodiment. Figure 2 This is an architecture diagram of ARPT in one embodiment. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0025] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.
[0026] It should be noted that, in this document, the reference to "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The presentation of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will understand that the embodiments described herein can be combined with other embodiments. The term "and / or" as used herein refers to any combination of one or more of the associated listed items, and all possible combinations, including such combinations.
[0027] Automated Recursive Partitioning Tree (ARPT)
[0028] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0029] In one embodiment, such as Figure 1 As shown, an automatic recursive meshing method for a domain-specific language for unstructured meshes is provided, which may include the following processing steps 1 to 7: Step 1: The user obtains the unstructured mesh and parallel operation parameters, and inserts or calls the conflict handling primitive interface in the front-end computation code.
[0030] Step 2: The program analysis module of the DSL converter performs syntax parsing on the source code of the target computing core, constructs an initial abstract syntax tree, and generates and standardizes code slices based on control flow and data flow analysis.
[0031] Step 3: The candidate list generation module of the DSL converter constructs a structured candidate element list based on the initial abstract syntax tree, and the abstract syntax tree construction module of the DSL converter constructs a domain-specific abstract syntax tree based on the candidate element list.
[0032] Step 4: The backend code generation module of the DSL converter generates conflict-free parallel target code based on the candidate element list and the domain-specific abstract syntax tree.
[0033] Step 5: The recursive partitioning module of the ARPT runtime library constructs an automatic recursive partitioning tree based on the grid topology data.
[0034] Step 6: The ARPT runtime library's grid data rearrangement module performs global renumbering and grid data rearrangement based on an automatic recursive partitioning tree.
[0035] Step 7: Runtime scheduling and execution of the task scheduling module of the ARPT runtime library.
[0036] The aforementioned automatic recursive partitioning method for domain-specific languages (DSLs) of unstructured grids proposes an automated recursive partitioning and data conflict resolution software architecture for shared-memory multi-core CPU platforms within the framework of DSLs and their converters. By uniformly describing the grid topology and indirect access patterns at the DSL level, it automatically constructs the task dependency structure for conflict resolution. Combined with global renumbering and data rearrangement mechanisms, it improves the parallel efficiency, data locality, and performance portability of unstructured grid applications on multi-core CPU platforms while ensuring numerical correctness, and reduces application development and maintenance costs.
[0037] In one embodiment, step 1 includes: the user analyzes the unstructured mesh domain-specific language framework mesh topology data and computes the kernel code; the mesh topology data includes at least: cell sets, face / edge sets, node sets, and the mapping relationships between them; the user encapsulates the unstructured mesh entity into set objects and mapping objects through the DSL interface module, and obtains the number of cores of the target multi-core CPU, mesh size parameters, and recursive partitioning strategy version information; the user inserts or calls conflict handling primitive interfaces in the front-end code.
[0038] In one embodiment, step 2 includes: starting the abstract syntax tree program analysis module within the DSL framework to perform syntax parsing on the source code of the target computation kernel containing indirect access and constructing an initial abstract syntax tree; the program analysis module of the DSL converter automatically extracts code slices related to unstructured grid loops from the complete program based on control flow and data flow analysis; the code slices include at least grid traversal loops, indirect memory access statements, and read / write permission declarations; the program analysis module of the DSL converter performs normalization processing on the extracted code slices, removes auxiliary statements unrelated to the target computation, retains key statements used to construct the parallel execution order and data dependencies, and forms a structured candidate code slice representation.
[0039] In one embodiment, step 3 includes: the candidate list generation module of the DSL converter traverses the abstract syntax tree of the candidate code slices, extracts domain-related key elements according to the node type, and organizes the extracted key elements into a candidate element list according to a predetermined hierarchical rule; the abstract syntax tree construction module of the DSL converter constructs a domain-specific abstract syntax tree based on the candidate element list, and aggregates several statements in the initial abstract syntax tree into logically complete code block nodes, with each code block node recording its internal grid traversal pattern, data access set, and mapping relationship.
[0040] In one embodiment, step 4 includes: the back-end code generation module of the DSL converter constructs a global conflict relationship model based on the indirect write access patterns recorded in the candidate element list and the mapping relationships between cells, faces / edges, and nodes in the mesh topology, treating iterations or cells that may be written to the same data location as conflicting element pairs; taking the domain-specific abstract syntax tree and conflicting element pairs as input, it generates an automatic recursive subdivision tree construction function based on the mesh topology and a global renumbering and mesh data rearrangement function based on the recursive subdivision tree; the back-end code generation module of the DSL converter takes the domain-specific abstract syntax tree as input, traverses the code block nodes representing multiple loops, and converts them into computational kernels executed on ARPT tree nodes, with each computational kernel accessing only the relevant computational data; the back-end code generation module of the DSL converter organizes the automatic recursive subdivision tree construction function, the renumbering and mesh data rearrangement function, and the computational kernels into multiple object code files and links them with the original DSL runtime library to form a complete conflict-free parallel execution program.
[0041] In one embodiment, step 5 includes: the recursive partitioning module of the ARPT runtime library takes the set of grid cells as the starting root node, and divides the set of cells corresponding to the root node into several sub-cell blocks based on preset block size parameters and branch number parameters; recursively partitions each sub-cell block, and stops partitioning when the size of the sub-cell block is less than a preset threshold, and marks the sub-cell block as a leaf node; for boundary cells with cross-sub-block data dependencies, the recursive partitioning module of the ARPT runtime library constructs isolation regions, aggregates the boundary cells or their contributions into separate isolators, and records the parent-child relationship and sibling relationship between the isolators and adjacent sub-cell block nodes in the recursive partitioning tree; at each node of the recursive partitioning tree, the recursive partitioning module of the ARPT runtime library records the cell index range, boundary cell set, parent node pointer and child node list corresponding to the node, forming a hierarchical task structure that can be used for scheduling.
[0042] In one embodiment, step 6 includes: the ARPT runtime library's grid data rearrangement module generating a new grid cell numbering scheme based on the leaf nodes and isolator nodes of the recursive partitioning tree; rearranging the grid cell data array according to the new grid cell numbers; and updating the cell-related mapping array according to the new grid cell numbering scheme, and establishing a bidirectional mapping table between the old and new numbers when necessary.
[0043] In one embodiment, step 7 includes: when the program starts, the ARPT runtime library's task scheduling module first initializes the recursive partitioning tree data structure, loads the tree node information into memory, and selects an appropriate task scheduling strategy based on the number of cores and NUMA structure of the multi-core CPU; when performing unstructured mesh computation, the ARPT runtime library's task scheduling module first schedules the sub-block computation kernels corresponding to each leaf node in parallel, executing them on different CPU cores, and only performing write operations on non-conflicting sub-blocks at the same time; when the sub-block computation of a certain level is completed, the ARPT runtime library's task scheduling module schedules the synchronization kernels corresponding to the isolator nodes in sequence according to the parent-child and sibling relationships recorded in the recursive partitioning tree, completing the merging and updating of cross-sub-block data; throughout the entire execution process, the ARPT runtime library's task scheduling module expands from top to bottom in the order of first executing non-isolated sub-blocks at the same level, and then executing the corresponding isolators; after completing the sub-block computation and isolator synchronization of all recursive levels, the ARPT runtime library's task scheduling module retains the finally updated physical quantities in the global data structure.
[0044] In one embodiment, the architecture diagram of ARPT is as follows: Figure 2 As shown, an automatic recursive partitioning method for a domain-specific language for unstructured meshes is provided. The specific steps include: Step S1: The DSL framework front-end interface module obtains the unstructured mesh and parallel operation parameters. Specific steps include: Step S1.1: The user analyzes the unstructured mesh domain-specific language (DSL) framework mesh topology data and computes the kernel code. The mesh topology data includes at least: cell sets, face / edge sets, node sets, and the mapping relationships between them.
[0045] Step S1.2: The user encapsulates the above-mentioned mesh entities into set objects and mapping objects through the DSL interface module, and obtains the number of cores of the target multi-core CPU, mesh size parameters, and recursive partitioning strategy version information.
[0046] Step S1.3: The user inserts or calls the conflict handling primitive interface in the front-end code, such as: op_solve_conflict_partition(mesh set, mesh mapping, number of multi-core cores, mesh size, policy version); when the user calls this primitive, it triggers the subsequent automatic recursive partitioning and conflict-free parallelization process.
[0047] Step S2: The DSL converter's program analysis module completes source code parsing and code segmentation. Specific steps include: Step S2.1: Start the abstract syntax tree program analysis module within the DSL framework to perform syntax parsing on the source code of the target computing kernel containing indirect access and construct the initial abstract syntax tree.
[0048] Step S2.2: Based on control flow and data flow analysis, the program analysis module automatically extracts code slices related to unstructured mesh loops from the complete program. The code slices include at least mesh traversal loops, indirect memory access statements, and read / write permission declarations.
[0049] Step 2.3: The program analysis module performs normalization processing on the extracted code slices, removes auxiliary statements that are irrelevant to the target computation, and retains key statements used to construct the parallel execution order and data dependencies, forming a structured candidate code slice representation.
[0050] Step S3: The DSL converter constructs a structured candidate list and a domain-specific abstract syntax tree. Specific steps include: Step S3.1: The candidate list generation module of the DSL converter traverses the abstract syntax tree of the candidate code slices and extracts domain-related key elements based on the node type (function call, assignment statement, loop structure, etc.), including: grid set identifier, mapping identifier, data object identifier, op_par_loop call information, and read / write / read / write access mode.
[0051] Step S3.2: The candidate list generation module of the DSL converter organizes the extracted key elements into a candidate element list according to a predetermined hierarchical rule, so that each list entry can simultaneously reflect the grid entity, access direction and access permission, and is used to describe a specific type of indirect access mode.
[0052] Step S3.3: The abstract syntax tree building module of the DSL converter constructs a domain-specific abstract syntax tree (DS-AST) based on the candidate element list. It aggregates several statements in the original syntax tree into logically complete code block nodes. Each code block node records the grid traversal pattern, data access set and mapping relationship contained within it, which are used to drive subsequent automatic code conversion and task decomposition.
[0053] Step S4: The back-end code generation module of the DSL converter generates conflict-free parallel computing code; specific steps include: Step S4.1: The backend code generation module constructs a global conflict relationship model based on the indirect write access patterns recorded in the candidate element list and the mapping relationship between cells, faces / edges, and nodes in the mesh topology. It treats iterations or cells that may be written to the same data location as conflicting element pairs.
[0054] Step S4.2: The backend code generation module takes the DS-AST and conflicting element pairs as input and generates an automatic recursive partitioning tree construction function based on grid topology. Step S4.3: The backend code generation module takes the DS-AST and conflicting element pairs as input and generates a global renumbering and data rearrangement function based on a recursive partitioning tree. Step S4.4: The backend code generation module takes DS-AST as input, traverses the code block nodes representing multiple loops, and converts them into computation kernels that are executed on ARPT tree nodes. Each computation kernel only accesses the relevant computation data.
[0055] Step S4.5: The backend code generation module organizes the generated partitioning function, renumbering and data rearrangement function, and calculation kernel function into multiple object code files, and links them with the original DSL runtime library to form a complete conflict-free parallel execution program.
[0056] Step S5: The recursive partitioning module in the ARPT runtime library constructs an automatic recursive partitioning tree based on the mesh topology; specific steps include: Step S5.1: The recursive partitioning module takes the set of grid cells as the starting root node, and divides the set of cells corresponding to the root node based on the preset block size parameters and branch number parameters to obtain several sub-cell blocks; each sub-cell block is used as a child node of the recursive partitioning tree (ARPT).
[0057] Step S5.2: The recursive subdivision module recursively executes step 5.2 for each sub-unit block. When the size of the sub-unit block is less than a preset threshold, the subdivision stops and the sub-unit block is marked as a leaf node.
[0058] Step S5.3: For boundary cells with cross-sub-block data dependencies, the recursive partitioning module constructs isolation regions, aggregates these boundary cells or their contributions into separate isolator nodes, and records the parent-child and sibling relationships between isolator nodes and adjacent sub-block nodes in the recursive partitioning tree to describe the synchronization order.
[0059] Step S5.4: The recursive decomposition module records the cell index range, boundary cell set, parent node pointer, and child node list for each node in the recursive decomposition tree, forming a hierarchical task structure that can be used for scheduling.
[0060] Step S6: The ARPT runtime library module's data rearrangement module performs global renumbering and data rearrangement based on a recursive partitioning tree; specific steps include: Step S6.1: The data rearrangement module generates a new grid cell numbering scheme based on the leaf nodes and isolator nodes of the ARPT tree, so that the cells in the same leaf node are as continuous in number as possible, and divides the cells corresponding to different leaf nodes into several continuous numbering intervals.
[0061] Step S6.2: The data rearrangement module rearranges the grid cell data array according to the new cell number, so that the cell data of the same sub-block is stored sequentially in memory, thereby improving cache hit rate and data locality.
[0062] Step S6.3: The data rearrangement module updates the mapping array related to the cells (such as face-to-cell mapping, cell-to-node mapping, etc.) according to the new cell numbering scheme, and establishes a bidirectional mapping table between the old and new numbers when necessary to maintain compatibility with the original data structure.
[0063] Step S7: The ARPT runtime library module's task scheduler completes runtime scheduling and execution. Specific steps include: Step S7.1: When the program starts, the runtime library first initializes the ARPT tree data structure, loads the tree node information into memory, and selects an appropriate task scheduling strategy based on the number of cores and NUMA structure of the multi-core CPU.
[0064] Step S7.2: When performing unstructured grid computation, the runtime library first schedules the sub-block computation kernels corresponding to each leaf node in parallel, executes them on different CPU cores, and performs write operations only on non-conflicting sub-blocks at the same time, thereby avoiding write conflicts on shared data.
[0065] Step S7.3: After the sub-block of a certain level is calculated, the runtime library schedules the synchronization kernel corresponding to the isolator node in turn according to the parent-child relationship and sibling relationship recorded in the ARPT tree to complete the merging and updating of cross-sub-block data.
[0066] Step S7.4: Throughout the execution process, the task scheduler unfolds from top to bottom in the order of "first executing non-isolated sub-blocks at the same level, then executing the corresponding isolators".
[0067] Step S7.5: After completing the sub-block calculations and isolator synchronization for all recursive levels, the runtime library retains the final updated physical quantities in the global data structure to provide input for subsequent time step progression or other physical process calculations.
[0068] The automatic recursive partitioning method proposed in this application for domain-specific languages for unstructured meshes employs an automatic recursive partitioning programming framework with a dual mechanism of recursive partitioning and global renumbering. This achieves transparent avoidance of write conflicts and system enhancement of data locality in DS-AST-driven static analysis and code generation. Furthermore, it integrates program dependency analysis, recursive partitioning, renumbering, and conflict-free parallel code generation within the DSL toolchain. The application layer only needs to call a fixed interface to handle conflicts, eliminating the need to manually write complex partitioning and synchronization logic in the business code. This effectively reduces development and maintenance costs and improves performance portability across different multi-core CPU platforms. Compared to manual solutions, ARPT significantly reduces implementation and maintenance costs. On real CFD benchmarks, developers can see a 99.22% reduction in SLOC. By offloading complex conflict handling to reusable converters and runtime, performance tests on four types of multi-core CPUs (Intel Xeon Gold 6258R, Intel Xeon Platinum 9242, Hygon C86 7285H, and HUAWEI Kunpeng 920) show that ARPT can achieve up to 1.72x performance acceleration, a 51.8% improvement in program-level IPC, and a 42.1% reduction in L1 cache misses. Furthermore, it exhibits faster residual decay and fewer threshold steps under a fixed step budget, validating the dual positive effects of locality improvement and conflict avoidance on efficiency and convergence.
[0069] It should be noted that, although the above Figure 1 The steps are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise explicitly stated in this document, there is no strict order in which these steps are executed; they can be performed in other orders. Furthermore, the above... Figure 1At least some of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0070] In one embodiment, an automatic recursive partitioning device for a domain-specific language for unstructured meshes is also provided. The device includes an input module, a DSL converter, and an ARPT runtime library module. The DSL converter includes a program analysis module, a candidate list generation module, an abstract syntax tree construction module, and a backend code generation module. The ARPT runtime library module includes a recursive partitioning module, a mesh data rearrangement module, and a task scheduling module.
[0071] The input module is used to obtain unstructured mesh and parallel operation parameters, and to insert or call conflict handling primitive interfaces in the front-end computation code.
[0072] The DSL converter is used to perform syntax parsing on the source code of the target computing kernel through the program analysis module, construct an initial abstract syntax tree, and generate and standardize code slices based on control flow and data flow analysis; the candidate list generation module constructs a structured candidate element list based on the initial abstract syntax tree; the abstract syntax tree construction module constructs a domain-specific abstract syntax tree based on the candidate element list; and the backend code generation module generates conflict-free parallel target code based on the candidate element list and the domain-specific abstract syntax tree.
[0073] The ARPT runtime library module is used to construct an automatic recursive subdivision tree based on grid topology data through the recursive subdivision module; to perform global renumbering and grid data rearrangement based on the automatic recursive subdivision tree through the grid data rearrangement module; and to schedule and execute tasks at runtime through the task scheduling module.
[0074] In one embodiment, the input module is further used for users to analyze unstructured mesh domain-specific language framework mesh topology data and compute kernel code; the mesh topology data includes at least: cell sets, face / edge sets, node sets, and the mapping relationships between them; users encapsulate unstructured mesh entities into set objects and mapping objects through the DSL interface module to obtain the number of cores of the target multi-core CPU, mesh size parameters, and recursive partitioning strategy version information; users insert or call conflict handling primitive interfaces in the front-end code.
[0075] In one embodiment, an abstract syntax tree (AST) program analysis module is initiated within the DSL framework. This DSL converter's program analysis module performs syntax parsing on the source code of the target computation kernel containing indirect accesses, constructing an initial AST. Based on control flow and data flow analysis, code slices related to unstructured grid loops are automatically extracted from the complete program. Each code slice includes at least grid traversal loops, indirect memory access statements, and read / write permission declarations. The extracted code slices are then normalized, removing auxiliary statements unrelated to the target computation and retaining key statements used to construct the parallel execution order and data dependencies, forming a structured candidate code slice representation.
[0076] In one embodiment, the candidate list generation module of the DSL converter is used to traverse the abstract syntax tree of the candidate code slices, extract domain-related key elements according to the node type, and organize the extracted key elements into a candidate element list according to a predetermined hierarchical rule; construct a domain-specific abstract syntax tree based on the candidate element list, and aggregate several statements in the initial abstract syntax tree into logically complete code block nodes. Each code block node records the grid traversal pattern, data access set, and mapping relationship contained within it.
[0077] In one embodiment, the backend code generation module of the DSL converter is used to construct a global conflict relationship model based on the indirect write access patterns recorded in the candidate element list and the mapping relationships between cells, faces / edges, and nodes in the mesh topology, treating iterations or cells that may be written to the same data location as conflicting element pairs; taking the domain-specific abstract syntax tree and conflicting element pairs as input, it generates an automatic recursive subdivision tree construction function based on the mesh topology and a global renumbering and mesh data rearrangement function based on the recursive subdivision tree; taking the domain-specific abstract syntax tree as input, it traverses the code block nodes representing multiple loops and converts them into computational kernels that execute on ARPT tree nodes, with each computational kernel accessing only the relevant computational data; the automatic recursive subdivision tree construction function, the renumbering and mesh data rearrangement function, and the computational kernels are uniformly organized into multiple object code files and linked with the original DSL runtime library to form a complete conflict-free parallel execution program.
[0078] In one embodiment, the recursive partitioning module of the ARPT runtime library is used to partition the set of cells corresponding to the root node, starting with a set of grid cells as the root node, based on preset block size parameters and branch number parameters, to obtain several sub-cell blocks; recursively partition each sub-cell block, stopping partitioning when the size of the sub-cell block is less than a preset threshold, and marking the sub-cell block as a leaf node; for boundary cells with cross-sub-block data dependencies, an isolation region is constructed, and the boundary cells or their contributions are aggregated into separate isolator nodes, and the parent-child relationship and sibling relationship between the isolator node and the adjacent sub-cell block node are recorded in the recursive partitioning tree; at each node of the recursive partitioning tree, the cell index range, boundary cell set, parent node pointer, and child node list corresponding to the node are recorded, forming a hierarchical task structure that can be used for scheduling.
[0079] In one embodiment, the grid data rearrangement module of the ARPT runtime library is used to generate a new grid cell numbering scheme based on the leaf nodes and isolator nodes of the recursive partitioning tree; rearrange the grid cell data array according to the new grid cell numbering; update the mapping array associated with the cell according to the new grid cell numbering scheme; and establish a bidirectional mapping table between the old and new numbers when necessary.
[0080] In one embodiment, upon program startup, the ARPT runtime library's task scheduling module first initializes the recursive partitioning tree data structure, loads the tree node information into memory, and selects an appropriate task scheduling strategy based on the number of cores in a multi-core CPU and the NUMA structure. During unstructured mesh computation, the sub-block computation kernels corresponding to each leaf node are first scheduled in parallel, executed on different CPU cores, with write operations performed only on non-conflicting sub-blocks at any given time. Once a sub-block computation at a certain level is completed, the synchronization kernels corresponding to the isolator nodes are scheduled sequentially according to the parent-child and sibling relationships recorded in the recursive partitioning tree to complete the merging and updating of cross-sub-block data. Throughout the execution process, the process unfolds from top to bottom, executing non-isolated sub-blocks at the same level first, followed by the corresponding isolators. After completing the sub-block computation and isolator synchronization for all recursive levels, the finally updated physical quantities are retained in the global data structure.
[0081] It is understood that for a detailed explanation of the automatic recursive partitioning device for domain-specific languages of unstructured meshes, please refer to the corresponding explanations of the embodiments of the automatic recursive partitioning method for domain-specific languages of unstructured meshes above, and will not be repeated here. Each module in the above-described automatic recursive partitioning device for domain-specific languages of unstructured meshes can be implemented entirely or partially through software, hardware, or a combination thereof. Each module can be embedded in hardware or independently of a device with data processing capabilities, or stored in software in the memory of the aforementioned device, so that the processor can call and execute the operations corresponding to each module. The aforementioned device can be, but is not limited to, various types of data processing computer devices already existing in the art.
[0082] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0083] The above embodiments are merely illustrative of several implementation methods of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of protection of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and all such modifications and improvements fall within the scope of protection of this application.
Claims
1. An automatic recursive partitioning method for a domain-specific language for unstructured meshes, characterized in that, Including the following steps: Step 1: The user obtains the unstructured mesh and parallel operation parameters, and inserts or calls the conflict handling primitive interface in the front-end computation code; Step 2: The program analysis module of the DSL converter performs syntax parsing on the source code of the target computing core, constructs an initial abstract syntax tree, and generates and standardizes code slices based on control flow and data flow analysis. Step 3: The candidate list generation module of the DSL converter constructs a structured candidate element list based on the initial abstract syntax tree, and the abstract syntax tree construction module of the DSL converter constructs a domain-specific abstract syntax tree based on the candidate element list; Step 4: The backend code generation module of the DSL converter generates conflict-free parallel target code based on the candidate element list and the domain-specific abstract syntax tree; Step 5: The recursive partitioning module of the ARPT runtime library constructs an automatic recursive partitioning tree based on the mesh topology data; Step 6: The ARPT runtime library's grid data rearrangement module performs global renumbering and grid data rearrangement based on an automatic recursive partitioning tree; Step 7: Runtime scheduling and execution of the ARPT runtime library's task scheduling module.
2. The automatic recursive partitioning method for unstructured mesh domain-specific languages according to claim 1, characterized in that, Step 1 includes: The user analyzes the unstructured mesh domain-specific language framework mesh topology data and computation kernel code; the mesh topology data includes at least: cell set, face / edge set, node set, and the mapping relationship between them; Users encapsulate the unstructured mesh entity into a set object and a mapping object through the DSL interface module to obtain the number of cores of the target multi-core CPU, mesh size parameters, and recursive partitioning strategy version information. Users can insert or call conflict handling primitive interfaces in the front-end code.
3. The automatic recursive partitioning method for unstructured mesh domain-specific languages according to claim 1, characterized in that, Step 2 includes: Within the DSL framework, the abstract syntax tree program analysis module is launched to perform syntax parsing on the source code of the target computing kernel containing indirect access and to construct the initial abstract syntax tree. The DSL converter's program analysis module automatically extracts code slices related to unstructured grid loops from the complete program based on control flow and data flow analysis; the code slices include at least grid traversal loops, indirect memory access statements, and read / write permission declarations; The program analysis module of the DSL converter normalizes the extracted code slices, removes auxiliary statements that are irrelevant to the target computation, and retains key statements used to construct the parallel execution order and data dependencies, forming a structured candidate code slice representation.
4. The automatic recursive partitioning method for unstructured mesh domain-specific languages according to claim 1, characterized in that, Step 3 includes: The candidate list generation module of the DSL converter traverses the abstract syntax tree of the candidate code slices, extracts domain-related key elements according to the node type, and organizes the extracted key elements into a candidate element list according to a predetermined hierarchical rule. The DSL converter's abstract syntax tree building module constructs a domain-specific abstract syntax tree based on the candidate element list. It aggregates several statements in the initial abstract syntax tree into logically complete code block nodes. Each code block node records the grid traversal pattern, data access set, and mapping relationship contained within it.
5. The automatic recursive partitioning method for unstructured mesh domain-specific languages according to claim 1, characterized in that, Step 4 includes: The backend code generation module of the DSL converter constructs a global conflict relationship model based on the indirect write access patterns recorded in the candidate element list and the mapping relationship between cells, faces / edges, and nodes in the mesh topology. It treats iterations or cells that may be written to the same data location as conflicting element pairs. Taking the domain-specific abstract syntax tree and conflicting element pairs as input, it generates an automatic recursive subdivision tree construction function based on the mesh topology and a global renumbering and mesh data rearrangement function based on the recursive subdivision tree. The backend code generation module of the DSL converter takes a domain-specific abstract syntax tree as input, traverses code block nodes representing multiple loops, and converts them into computation kernels that are executed on ARPT tree nodes. Each computation kernel only accesses the relevant computation data. The back-end code generation module of the DSL converter will automatically recursively organize the tree construction function, renumbering and grid data rearrangement function, and computation kernel into multiple object code files, and link them with the original DSL runtime library to form a complete conflict-free parallel execution program.
6. The automatic recursive partitioning method for unstructured mesh domain-specific languages according to claim 1, characterized in that, Step 5 includes: The recursive subdivision module of the ARPT runtime library starts with a set of mesh cells as the root node. Based on preset block size parameters and branch number parameters, it divides the set of cells corresponding to the root node into several sub-cell blocks. It recursively subdivides each sub-cell block. When the size of the sub-cell block is less than a preset threshold, the subdivision stops and the sub-cell block is marked as a leaf node. For boundary cells with cross-sub-block data dependencies, the recursive partitioning module of the ARPT runtime library constructs isolation regions, aggregates the boundary cells or their contributions into individual isolators, and records the parent-child and sibling relationships between the isolators and adjacent sub-block nodes in the recursive partitioning tree. The recursive decomposition module of the ARPT runtime library records the cell index range, boundary cell set, parent node pointer, and child node list for each node in the recursive decomposition tree, forming a hierarchical task structure that can be used for scheduling.
7. The automatic recursive partitioning method for unstructured mesh domain-specific languages according to claim 6, characterized in that, Step 6 includes: The ARPT runtime library's grid data rearrangement module generates a new grid cell numbering scheme based on the leaf nodes and isolator nodes of the recursive partitioning tree; and rearranges the grid cell data array according to the new grid cell numbers. The ARPT runtime library's grid data rearrangement module updates the mapping array associated with the cells according to the new grid cell numbering scheme, and establishes a bidirectional mapping table between the old and new numbers when necessary.
8. The automatic recursive partitioning method for unstructured mesh domain-specific languages according to claim 6, characterized in that, Step 7 includes: When the program starts, the task scheduling module of the ARPT runtime library first initializes the recursive partitioned tree data structure, loads the tree node information into memory, and selects an appropriate task scheduling strategy based on the number of cores and NUMA structure of the multi-core CPU. When performing unstructured grid computation, the task scheduling module of the ARPT runtime library first schedules the sub-block computation kernels corresponding to each leaf node in parallel, executes them on different CPU cores, and performs write operations only on non-conflicting sub-blocks at the same time. Once the sub-block calculation at a certain level is completed, the ARPT runtime library's task scheduling module schedules the synchronization kernels corresponding to the isolator nodes in sequence according to the parent-child and sibling relationships recorded in the recursive partitioning tree, thereby completing the merging and updating of cross-sub-block data. Throughout the execution process, the ARPT runtime library's task scheduling module unfolds from top to bottom in the order of first executing non-isolated sub-blocks at the same level, and then executing the corresponding isolators; After completing the sub-block calculations and isolator synchronization for all recursive levels, the ARPT runtime library's task scheduling module retains the final updated physical quantities in the global data structure.
9. An automatic recursive partitioning device for a domain-specific language for unstructured meshes, characterized in that, include: Input module, DSL converter, and ARPT runtime library module; The DSL converter includes: a program analysis module, a candidate list generation module, an abstract syntax tree construction module, and a backend code generation module; the ARPT runtime library module includes: a recursive decomposition module, a grid data rearrangement module, and a task scheduling module; The input module is used to obtain unstructured mesh and parallel operation parameters, and to insert or call conflict handling primitive interfaces in the front-end computation code. The DSL converter is used to perform syntax parsing on the source code of the target computing kernel through the program analysis module, construct an initial abstract syntax tree, generate and standardize code slices based on control flow and data flow analysis; construct a structured candidate element list based on the initial abstract syntax tree through the candidate list generation module; construct a domain-specific abstract syntax tree based on the candidate element list through the abstract syntax tree construction module; and generate conflict-free parallel target code through the backend code generation module based on the candidate element list and the domain-specific abstract syntax tree. The ARPT runtime library module is used to construct an automatic recursive subdivision tree based on grid topology data through the recursive subdivision module; to perform global renumbering and grid data rearrangement based on the automatic recursive subdivision tree through the grid data rearrangement module; and to schedule and execute tasks at runtime through the task scheduling module.