Single-thread program parallel processing method
By identifying and marking code segments that can be executed in parallel and generating control blocks, the problem of low computing speed of single-threaded programs is solved, parallel processing of single-threaded programs is realized, and the computing speed is improved.
Patent Information
- Application Number
- CN202410952999.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-08-15
- Filing Date
- 2024-07-16
- Publication Date
- 2024-11-08
AI Technical Summary
Single-threaded programs have low computing speed due to the continuous sequential execution of program paths, and cannot fully utilize the parallel processing capabilities of multi-core processors.
By marking the code segment, identifying the code segment that can be executed in parallel, and generating control blocks to control its parallel execution, judging the dependencies between the code segments, adding tags to implement parallel processing, and executing the code segments separately with multi-core processors, optimizing The execution order of the code segment.
The operation speed of a single-threaded program is improved, and the overall operation time of the program is reduced by processing multiple code segments in parallel.
Smart Images

Figure CN118916008A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to a single-thread program parallel processing method. Background Art
[0002] Single-threaded programs have the characteristics of system stability and strong scalability.
[0003] However, during the execution of a single-threaded program, the program paths taken are arranged in a continuous order, and the previous ones must be processed before the latter ones can be executed.
[0004] This results in a lower execution speed for single-threaded programs. Summary of the invention
[0005] In order to improve the operation speed of a single-threaded program, the present application provides a single-threaded program parallel processing method.
[0006] This application provides a single-threaded program parallel processing method, which adopts the following technical solution: A single-thread program parallel processing method comprises the following steps: Identify N code segments based on the markers marking the code segments, and the N code segments are used to be executed in parallel; The identified N code segments are translated into executable codes, and a control block for controlling the parallel execution of the N code segments is generated.
[0007] By adopting the above technical solution, the source code of the single-threaded program is marked to obtain multiple code segments that can be executed in parallel, and the N code segments are translated into executable codes to control the parallel execution of the N code segments, thereby realizing parallel processing of the single-threaded program, which is beneficial to improving the operation speed of the single-threaded program.
[0008] Preferably, the method further comprises the following steps: Based on the dependencies between code segments, determine whether the code segments can be executed in parallel; When it is determined that the code segment can be executed in parallel, a marker is added.
[0009] Preferably, the dependency relationship includes whether there are mutually dependent parameters, whether operations must be performed sequentially, and whether there is a causal relationship.
[0010] Preferably, the control block is used to mark when the code segment completes the operation.
[0011] By adopting the above technical solution, after the parallel processing of N code segments is completed based on the identification, the parallel processing of the next group of N code segments is executed.
[0012] Preferably, the control block is used to control the execution of a specific code segment, and the specific code segment is any executable code segment among all code segments to be executed.
[0013] By adopting the above technical solution, the time required for each operation module to execute different code segments may vary. If any operation module is idle, the idle operation module immediately executes the subsequent code segment, thereby reducing the program operation time.
[0014] Preferably, the control block is used to determine whether the code segment is executable based on the code segment execution condition.
[0015] By adopting the above technical solution, the control execution of a specific code segment is achieved.
[0016] In summary, the present application includes at least one of the following beneficial technical effects: 1. Mark the source code of the single-threaded program to obtain multiple code segments that can be executed in parallel, and translate N code segments into executable code to control the parallel execution of N code segments, thus realizing the parallel processing of the single-threaded program, which is beneficial to improving the operation speed of the single-threaded program; 2. After the parallel processing of the N code segments is completed based on the identification, the parallel processing of the next group of N code segments is executed. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a flowchart of the single-thread program parallel processing method in Example 1. DETAILED DESCRIPTION
[0018] The following is combined with Figure 1 This application is described in further detail.
[0019] The embodiment of the present application discloses a single-threaded program parallel processing method.
[0020] Example 1 Reference Figure 1 , the single-thread program parallel processing method includes the following steps: S10, identifying N code segments based on the markers marking the code segments, and the N code segments are used to be executed in parallel.
[0021] Before step S10, the following steps are included: S01, judging whether the code segments can be executed in parallel based on the dependency relationship between the code segments.
[0022] The dependencies include whether there are interdependent parameters, whether operations must be performed one after another, whether there is a causal relationship, etc.
[0023] For example, in a single-threaded program, it includes code segment 1: A=a1+a2; code segment 2: B=b1+b2; code segment 3: C=A+…;…
[0024] If a1 and a2 are not associated with b1 and b2 respectively, it is determined that there is no dependency between code segment 1 and code segment 2, and further it is determined that code segment 1 and code segment 2 can be executed in parallel.
[0025] For example: in a single-threaded program, it includes code segment 1: A=a1+a2; code segment 2: B=A+b2; code segment 3: C=A+…;…
[0026] It is determined that there is a dependency relationship between code segment 1 and code segment 2, and further that code segment 1 and code segment 2 cannot be executed in parallel.
[0027] Moreover, when making judgments, the judgment is mainly based on automatic judgment by the program; if necessary, it can be assisted by manual judgment.
[0028] S02: When it is determined that the code segments can be executed in parallel, a marker is added.
[0029] For example, you can use the coroutine marker to mark code segments that can be executed in parallel; you can also use async, etc., as long as you can mark these code segments as being able to be executed in parallel.
[0030] S20, translating the identified N code segments into executable codes, and generating a control block for controlling the parallel execution of the N code segments.
[0031] Specifically, multiple cores of the control processor are respectively controlled to execute N code segments, so as to control the parallel execution of the N code segments.
[0032] At the same time, the control block is used to mark when the code segment completes the operation, and when the number of marks is equal to N, it is determined that all N code segments have completed the operation.
[0033] It is used to implement parallel processing of the next group of N code segments after completing the parallel processing of N code segments.
[0034] The implementation principle of a single-threaded program parallel processing method in an embodiment of the present application is: based on the dependency relationship between code segments, the source code of the single-threaded program is marked to obtain multiple code segments that can be executed in parallel, and the N code segments are translated into executable codes to control the parallel execution of the N code segments, thereby realizing the parallel processing of the single-threaded program, which is beneficial to improving the operation speed of the single-threaded program.
[0035] Example 2 The difference between this embodiment and embodiment 1 is that the control block is used to determine whether the code segment is executable based on the code segment execution condition. The control block is used to control the execution of a specific code segment, which is any executable code segment among all the code segments to be executed.
[0036] The code segment execution conditions include dependency, causal relationship, data relationship, etc. with the executing code segment.
[0037] Specifically, the control block controls multiple cores of the processor to execute N code segments respectively; When a core is in an idle state (or ready to execute the next code segment), the control block is used to control the core to execute any executable code segment among all the code segments to be executed.
[0038] The control block is used to mark when the code segment completes the operation, and whether the core is in an idle state can be determined based on the mark.
[0039] Example 3 The difference between this embodiment and embodiment 2 is that: The control block is used to control the execution of a specific code segment when M identifiers are detected, where 1≤M<N; The control block is used to control the execution of the next group of N specific code segments in a parallel processing manner when N identifiers are detected.
[0040] The above are all preferred embodiments of the present application, and the protection scope of the present application is not limited thereto. Therefore, any equivalent changes made according to the structure, shape, and principle of the present application should be included in the protection scope of the present application.
Claims
1. A single-thread program parallel processing method, characterized in that: The following steps are involved: Identify N code segments based on the markers marking the code segments, and the N code segments are used to be executed in parallel; The identified N code segments are translated into executable codes, and a control block for controlling the parallel execution of the N code segments is generated.
2. The single-thread program parallel processing method according to claim 1, characterized in that: The following steps are also included: Based on the dependencies between code segments, determine whether the code segments can be executed in parallel; When it is determined that the code segments can be executed in parallel, the marker is added.
3. The single-thread program parallel processing method according to claim 2, characterized in that: The dependency relationship includes whether there are mutually dependent parameters, whether operations must be performed one after another, and whether there is a causal relationship.
4. The single-thread program parallel processing method according to claim 1, characterized in that: The control block is used to mark when the code segment completes the operation.
5. The single-thread program parallel processing method according to claim 1, characterized in that: The control block is used to control the execution of a specific code segment, where the specific code segment is any executable code segment among all code segments to be executed.
6. The single-thread program parallel processing method according to claim 5, characterized in that: The control block is used to determine whether the code segment is executable based on the code segment execution condition.
