Disclosure of Invention
The invention solves the problems that the current calculation method of the simulation software in the prior art has at least one aspect of low CPU/memory utilization rate, long task response time and poor user experience.
In order to solve the problems, the invention provides a Monte Carlo simulation method based on multi-core parallel atomic oxygen or ultraviolet flux, which comprises the following steps:
step S1, acquiring the number of cores of a spacecraft simulation software operation platform, and determining the number of parallel tasks according to the number of cores;
step S2, respectively establishing sub-threads for each core participating in parallel computation according to the computation item category, distributing computation tasks, and distributing statistical space for each sub-thread according to the computation item category;
Step S3, a main thread of the spacecraft simulation software operation platform establishes a shared variable, and the main thread locks or unlocks the shared variable according to the completion result of each sub-thread on the calculation task;
and S4, the main thread outputs a calculation result according to the completion result of all the sub threads on the calculation task.
Preferably, in step S1, the determining the number of parallel tasks according to the number of cores includes:
when the number of cores is smaller than or equal to a first threshold value, a multi-core parallel mechanism is not started;
when the number of cores is greater than a first threshold and less than or equal to a second threshold, the number of parallel tasks is the number of cores-1;
And when the number of cores is larger than a second threshold value, the number of parallel tasks is the number of cores-2.
Preferably, in step S2, the allocating a statistical space for each of the sub-threads includes allocating a statistical space for calculating a result and a result distribution for each of the sub-threads.
Preferably, in step S2, the item category includes atomic oxygen flux or ultraviolet flux.
Preferably, in step S2, when the atomic oxygen flux is calculated, the sub-threads are respectively established for each core participating in parallel calculation, and the total number of random experiments is equally distributed to each sub-thread.
Preferably, in step S2, when calculating the atomic oxygen flux, an independent memory space is allocated for each of the sub-threads for the calculation result and the statistics of the result distribution.
Preferably, in step S2, when the uv flux is calculated, the sub-threads are respectively established for each core participating in parallel calculation, and the spacecraft surface subdivision grid is equally distributed to each sub-thread according to the total number.
Preferably, in step S2, when calculating the uv flux, an independent memory space is allocated for each of the sub-threads for the statistics of the result distribution, and each of the sub-threads uses a shared memory space for the statistics of the calculation result.
Preferably, in step S3, the main thread locks or unlocks the shared variable according to the completion result of each sub-thread on the computing task, including that after the sub-thread finishes computing, the main thread starts to access the shared variable, locks the shared variable, and after the sub-thread finishes accessing the shared variable, the main thread unlocks the shared variable.
Preferably, in step S4, the main thread outputs a calculation result according to the completion result of all the sub-threads on the calculation task, including aggregating the calculation results of all the sub-threads by the main thread after all the sub-threads complete the calculation task, and outputting a final calculation result and result distribution data.
Compared with the prior art, the Monte Carlo simulation method based on the multi-core parallel atomic oxygen or ultraviolet flux has the advantages that the Monte Carlo simulation method based on the multi-core parallel atomic oxygen or ultraviolet flux accelerates the Monte Carlo simulation calculation process of the atomic oxygen/ultraviolet irradiation flux on the surface of the spacecraft by reasonably dividing calculation tasks, reasonably utilizing a lock mechanism to avoid data writing conflict and other technical means, has simple steps, is easy to realize, can greatly improve the CPU/memory utilization ratio under the condition of not changing calculation precision, further greatly reduces the time and cost of Monte Carlo simulation, can also improve the accuracy of the atomic oxygen/ultraviolet irradiation flux by thinning the surface split grid of the spacecraft or increasing random experiment total number in the same calculation time, and reduces the calculation, use and research costs of the atomic oxygen/ultraviolet irradiation flux on the surface of the spacecraft, thereby having great significance. The method has obvious advantages and wide application prospects in the popularization, teaching and demonstration of spacecraft simulation software and the technical application of the degradation/undercut effect of spacecraft surface coating materials.
Detailed Description
The technical solutions of the embodiments of the present application will be clearly and thoroughly described below with reference to the accompanying drawings.
In the description of embodiments of the present application, the term "description of some embodiments" means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present application. In this specification, schematic representations of the above terms do not necessarily refer to the same implementations or examples. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
It should also be noted that in the description of the embodiments of the present application, the term "comprises/comprising" or any other variation thereof is intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal device. Without further limitation, an element defined by the phrase "comprising" does not exclude that an additional identical element is present in a process, method, article or terminal device comprising the element.
As shown in fig. 1, the embodiment of the invention provides a monte carlo simulation method based on multi-core parallel atomic oxygen or ultraviolet flux, which comprises the following steps:
step S1, acquiring the number of cores of a spacecraft simulation software operation platform, and determining the number of parallel tasks according to the number of cores;
step S2, respectively establishing sub-threads for each core participating in parallel computation according to the computation item category, distributing computation tasks, and distributing statistical space for each sub-thread according to the computation item category;
Step S3, a main thread of the spacecraft simulation software operation platform establishes a shared variable, and the main thread locks or unlocks the shared variable according to the completion result of each sub-thread on the calculation task;
and S4, the main thread outputs a calculation result according to the completion result of all the sub threads on the calculation task.
According to the embodiment, the Monte Carlo simulation method is modified, data sharing and data collection in calculation tasks are reasonably distributed on the premise of not changing calculation results, and the Monte Carlo simulation process is accelerated by fully utilizing a modern computer multi-core parallel architecture, so that the Monte Carlo simulation method is suitable for teaching and displaying scenes on a common desktop and suitable for large-scale simulation experiment scenes.
In some embodiments, in step S1, the determining the number of parallel tasks according to the number of cores includes:
when the number of cores is smaller than or equal to a first threshold value, a multi-core parallel mechanism is not started;
when the number of cores is greater than a first threshold and less than or equal to a second threshold, the number of parallel tasks is the number of cores-1;
And when the number of cores is larger than a second threshold value, the number of parallel tasks is the number of cores-2.
In some preferred embodiments, the first threshold is 2 and the second threshold is 4, thereby enabling a reasonable division of the computing tasks according to the number of cores, saving both costs and increasing computing time.
In some embodiments, in step S2, the assigning statistical space to each of the sub-threads includes assigning statistical space for calculating results and result distributions to each of the sub-threads.
In some embodiments, in step S2, the item category includes atomic oxygen flux or ultraviolet flux. Therefore, the method can realize the simulation calculation of atomic oxygen flux and ultraviolet flux, and has wide application range.
In some embodiments, in step S2, when calculating the atomic oxygen flux, the sub-threads are respectively established for each core participating in parallel calculation, and the random experiment total number is equally distributed to each sub-thread. And allocating independent memory space for each sub-thread for statistics of the calculation result and result distribution. Therefore, task allocation and calculation data storage can be reasonably carried out, the CPU/memory utilization rate is improved, and time and cost are saved.
In other embodiments, in step S2, when the uv flux is calculated, the sub-threads are respectively established for each core participating in parallel calculation, and the spacecraft surface subdivision grid is equally distributed to each of the sub-threads according to the total number. And allocating independent memory space for each sub-thread for statistics of the result distribution, and each sub-thread uses shared memory space for statistics of the calculation result. Therefore, task allocation and calculation data storage can be reasonably carried out, the CPU/memory utilization rate is improved, and time and cost are saved.
In some embodiments, in step S3, the main thread locks or unlocks the shared variable according to the completion result of each sub-thread on the computing task, including that after the computation of one sub-thread is finished, the main thread starts to access the shared variable, and at this time, the main thread locks the shared variable to prevent other sub-threads from accessing the shared variable, and after the sub-thread completes the access to the shared variable, the main thread unlocks the shared variable to allow other sub-threads to access the shared variable. Therefore, the data writing conflict is avoided by reasonably utilizing a lock mechanism, and the accuracy of the calculation result is affected.
In some embodiments, in step S4, the main thread outputs a calculation result according to the completion result of all the sub-threads on the calculation task, including aggregating the calculation results of all the sub-threads by the main thread after all the sub-threads complete the calculation task, and outputting a final calculation result and result distribution data. Therefore, by aggregating the data after multi-core parallelization, the CPU/memory utilization rate is improved, and the calculation time is greatly reduced.
In order to verify the effectiveness of the Monte Carlo simulation method based on the atomic oxygen or ultraviolet flux of the multi-core parallel in the embodiment, the Monte Carlo simulation method based on the atomic oxygen or ultraviolet flux of a single core is adopted for calculation by adopting the same grid density, the same particle number and the same particle reflection number, and the Monte Carlo simulation method based on the atomic oxygen or ultraviolet flux of the single core is used as comparison. Fig. 2-5 show, fig. 2 is a schematic diagram of a calculation result of a monte carlo simulation method based on single core atomic oxygen flux in an embodiment of the present invention, wherein a calculation time under a single core is 666.234 seconds, fig. 3 is a schematic diagram of a calculation result of a monte carlo simulation method based on multi-core parallel atomic oxygen flux in an embodiment of the present invention, a calculation time under a dual-core 4 thread is 175.339 seconds, fig. 4 is a schematic diagram of a calculation result of a monte carlo simulation method based on single core ultraviolet flux in an embodiment of the present invention, a calculation time under a single core is 251.648 seconds, and fig. 5 is a schematic diagram of a calculation result of a monte carlo simulation method based on multi-core parallel ultraviolet flux in an embodiment of the present invention, and a calculation time under a dual-core 4 thread is 70.263 seconds. In fig. 2 and 3, the size of the atomic oxygen flux is represented by the change in the shade of the color, the darker the color is, the larger the atomic oxygen flux is, and in fig. 4 and 5, the size of the ultraviolet irradiation flux is represented by the change in the shade of the color, the darker the color is, and the larger the ultraviolet irradiation flux is. As can be seen from the figure, the monte carlo simulation method based on the multi-core parallel atomic oxygen or ultraviolet flux in the embodiment is basically consistent with the calculation result of the monte carlo simulation method based on the single-core atomic oxygen or ultraviolet flux.
Therefore, the Monte Carlo simulation method based on the multi-core parallel atomic oxygen or ultraviolet flux in the embodiment accelerates the Monte Carlo simulation calculation process of the atomic oxygen/ultraviolet irradiation flux on the surface of the spacecraft by reasonably dividing calculation tasks, reasonably utilizing a lock mechanism to avoid data writing conflict and other technical means, has simple steps, is easy to realize, can greatly improve the CPU/memory utilization rate under the condition of not changing calculation precision, further greatly reduces the time and cost of Monte Carlo simulation, can also improve the precision of the atomic oxygen/ultraviolet irradiation flux by thinning the surface of the spacecraft or increasing random experiment total number in the same calculation time, and reduces the calculation, use and research costs of the atomic oxygen/ultraviolet irradiation flux on the surface of the spacecraft. The method has obvious advantages and wide application prospects in the popularization, teaching and demonstration of spacecraft simulation software and the technical application of the degradation/undercut effect of spacecraft surface coating materials.
Although the present disclosure is disclosed above, the scope of the present disclosure is not limited thereto. Various changes and modifications may be made by one skilled in the art without departing from the spirit and scope of the disclosure, and these changes and modifications will fall within the scope of the disclosure.