Distributed simulation method for modelica
By adopting a component-based distributed simulation approach on the Modelica simulation platform, and utilizing execution containers and lightweight communication protocols, the problems of long simulation time and difficult node deployment in existing technologies are solved, achieving efficient and flexible distributed simulation computing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA THREE GORGES UNIV
- Filing Date
- 2022-11-08
- Publication Date
- 2026-04-24
AI Technical Summary
The existing Modelica simulation platform is time-consuming and inefficient when performing complex simulations, and the deployment and expansion of distributed computing nodes are difficult. Existing distributed computing frameworks such as Hadoop and Spark require all computing modules to be installed on all nodes, making the nodes too cumbersome.
A distributed simulation method not based on remote procedure call technology is adopted. By installing execution containers on distributed computing nodes and using components as scheduling units, tasks are distributed in the form of task packages containing configuration files, dynamic libraries and runtime data. This avoids installing cumbersome system environments on nodes, achieving lightweight computing nodes, and using UDP and TCP protocols for communication.
It improves simulation efficiency, reduces the simulation calculation time of the master node, makes the computing nodes easy to dynamically expand, has an efficient communication protocol, adapts to the configuration modeling of the Modelica simulation platform, and supports lightweight and flexible distributed simulation.
Smart Images

Figure CN115795807B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer simulation, specifically relating to a distributed simulation method for Modelica. Background Technology
[0002] Modelica is an object-oriented, multi-domain unified modeling language suitable for modeling large-scale, complex, heterogeneous physical systems. Models described using Modelica are parsed, transformed, and compiled to generate executable simulation programs based on differential equations. These simulation programs include general differential equation solving algorithms; executing the solutions yields the time-varying characteristics of the model variables.
[0003] Modelica supports model development across multiple fields, including electrical, mechanical, thermodynamic, hydraulic, biological, and control engineering. By using a unified language to describe models from various domains, it significantly reduces the difficulty of model integration. Currently, Modelica is widely used in numerous engineering fields such as aerospace, automotive, nuclear energy, energy, and control.
[0004] Current simulation platforms using the Modelica language include MWorks, Dymola, and OpenModelica. These platforms primarily offer functions such as graphical modeling, Modelica-based model description, compilation to generate simulation systems, running the simulation systems to obtain simulation results, and visualization of those results. However, most of these platforms do not consider simulation performance; running simulations on a single machine for complex models is time-consuming and inefficient.
[0005] To address the aforementioned issues, this paper studies a distributed simulation method for the Modelica language simulation platform. This distributed simulation method uses components as the scheduling unit. The components that can be scheduled for execution on distributed system node computers are Modelica components encapsulated from dynamic library functions. During simulation execution, the distributed coordinator recommends computing nodes based on a scheduling algorithm. The simulation platform distributes task packages, consisting of configuration files, task data, and task dynamic libraries, to distributed nodes on the local area network for execution. After receiving the task package, the distributed nodes decompress it, execute it according to the configuration file description, and then send the execution results back to the master node. The master node summarizes the results and completes the simulation, thus achieving distributed parallel execution of simulation tasks and improving simulation performance. Summary of the Invention
[0006] The technical problem of this invention is that the existing simulation method of the Modelica simulation platform, which compiles the simulation model to generate a simulation program and then executes the simulation program on the local machine to obtain the simulation results, is time-consuming and inefficient when performing complex simulations.
[0007] Existing distributed computing frameworks such as Hadoop and Spark primarily rely on Remote Procedure Call (RPC) to achieve distributed computing. Distributed computing nodes, like the master node, need to install all the necessary computing modules. However, with the Modelica simulation platform, since the modules required for computation are defined by the user through configuration, using RPC would necessitate pre-installing all available modules on each node's computer. This would mean all distributed nodes must have the Modelica simulation platform installed, making the nodes overly cumbersome and limiting the number of nodes capable of performing distributed simulations. This significantly increases the difficulty of deploying and expanding computing nodes.
[0008] The purpose of this invention is to address the aforementioned problems by providing a distributed simulation method for Modelica that is not based on remote procedure call technology. This method involves installing execution containers capable of running regular executable programs on distributed computing node computers for distributed simulation computation; using components as the scheduling unit for distributed simulation; and distributing tasks from the master node computer to the computing node computers in the form of task packages containing configuration files, dynamic libraries, and runtime data. This avoids installing cumbersome system environments, scheduling response modules, and functional software modules on the computing nodes, achieving lightweight computing nodes, improving simulation efficiency, and facilitating dynamic expansion of the computing nodes.
[0009] The technical solution of this invention is a distributed simulation method for Modelica, which includes the following steps:
[0010] Step 1: Compile the functions written in C / C++ and Fortran into dynamic libraries, and encapsulate the dynamic libraries into components that can be used on the Modelica simulation platform;
[0011] Step 2: Use components in the Modelica simulation platform to build a simulation model, set whether to enable distributed, offline, and online simulation modes, as well as the simulation step size and simulation variables, and compile to generate the simulation program;
[0012] Step 3: In distributed simulation mode, when the master node executes the simulation program, it schedules tasks on a component-by-component basis, generates configuration files and simulation data from the parameters of the dynamic library functions, and packages the configuration files, dynamic libraries, and simulation data.
[0013] Step 4: The master node requests task scheduling from the distributed coordinator. After receiving the task scheduling request, the distributed coordinator recommends computing nodes according to the scheduling algorithm. The master node communicates with the computing nodes to complete the task package distribution. After receiving the task package, the computing node executes the computing task and sends the execution result back to the master node. The master node then summarizes the results.
[0014] Step 4.1: After the distributed coordinator starts, it broadcasts its own IP address to the compute nodes and master node computers via the UDP protocol;
[0015] Step 4.2: The compute node computer connects to the distributed coordinator based on the IP address of the distributed coordinator obtained from the UDP message;
[0016] Step 4.3: After the computing node computer connects to the distributed coordinator, it sends its status information to the distributed coordinator. The computing node connected to the distributed coordinator waits for the master node to connect on the preset port.
[0017] Step 4.4: The master node computer connects to the distributed coordinator based on the IP address of the distributed coordinator obtained through UDP communication;
[0018] Step 4.5: The master control node computer periodically requests the status list of currently online computing node computers from the distributed coordinator. When there is a computing task, it sends a request task scheduling packet to the distributed coordinator. The coordinator sends the recommended IP address of the computing node computer to the master control node computer according to the scheduling algorithm, and the master control node computer connects to the computing node computer.
[0019] Step 4.6: The master control node computer sends a task package to the compute node computer. After receiving the task package, the compute node computer sends the percentage of task execution to the master control node computer every time T1. If the master control node computer client does not receive the progress package within time T2, it terminates the task execution and re-requests task scheduling from the distributed coordinator.
[0020] Step 4.7: The master control node computer receives the running progress packet from the compute node computer, updates the task execution progress, and continues until it receives the task execution result packet, then disconnects.
[0021] Step 4.8: The master control node computer receives the task execution result packet from the compute node computer, summarizes and uses the results, and completes the subsequent simulation. If the current simulation mode is offline simulation, the output results of the simulation model are displayed in the simulation window after the simulation ends; if the current simulation mode is real-time simulation, the master control node computer processes the obtained data and then displays it to the user through the real-time simulation window.
[0022] Preferably, the communication protocol between the distributed coordinator and the computing node computers specifically includes:
[0023] (a) Computing node computer side:
[0024] 1.1) After the compute node computer starts up, it uses the UDP communication protocol to broadcast a request for the coordinator's IP address to the local area network; if the compute node computer fails to obtain the IP address, it resends the UDP request packet every time interval T1 until it obtains the IP address successfully.
[0025] 1.2) After the computing node computer obtains the coordinator's IP address, it establishes a TCP connection on the specified port and sends a heartbeat packet containing CPU and memory usage information to the coordinator every T1 time interval.
[0026] (ii) Distributed Coordinator Side:
[0027] 2.1) After the distributed coordinator starts, it enters a connection-waiting state on the designated port; at the same time, it listens for UDP protocol packets.
[0028] 2.2) Upon receiving a UDP packet from the compute node requesting an IP address, send a response packet to return the local IP address;
[0029] 2.3) Upon receiving a connection request from a computing node computer on the specified port, a TCP connection is established;
[0030] 2.4) If a heartbeat packet is received from a compute node computer, the status of the compute node computer is recorded in the online list. If no heartbeat packet is received from a compute node computer for three consecutive times, the compute node computer is removed from the online list.
[0031] Preferably, the communication protocol between the distributed coordinator and the master node computer includes:
[0032] (a) Main control node computer:
[0033] 1.1) After the master node computer starts up, it uses the UDP protocol to broadcast a request for the coordinator's IP address to the local area network; if the IP address acquisition fails, it resends the UDP request packet every time interval T1 until it is successfully acquired;
[0034] 1.2) After obtaining the IP address, the master node computer acts as a client to connect to the coordinator via the IP address and the specified port number; if the connection fails, it will automatically reconnect to the coordinator at interval T1.
[0035] 1.3) After a successful connection, the master node computer requests the list of currently online computing nodes and the status of CPU and memory from the coordinator every time interval T2, for display on the simulation platform;
[0036] 1.4) When the master node computer has a computing task, it sends a task scheduling request packet to the coordinator;
[0037] 1.5) After receiving the request scheduling response packet, the master control node computer starts communication with the computing node computer through the IP address of the computing node computer provided in the response packet; if the communication between the master control node computer and the computing node computer fails, it will return to step 1.4) to request scheduling again.
[0038] (ii) Distributed Coordinator Side:
[0039] 2.1) After the distributed coordinator starts, it enters a connection-waiting state on the designated port; at the same time, it listens for UDP packets.
[0040] 2.2) Upon receiving a UDP request for an IP address, a response packet is sent to return the local machine's IP address;
[0041] 2.3) Upon receiving a connection request from a client on the specified port on the master computer, a TCP connection is established;
[0042] 2.4) Upon receiving a request for an online computing node, return a list of online computing node computers;
[0043] 2.5) Upon receiving a request task scheduling packet, the first-come, first-served (FFS) scheduling algorithm, the shortest job first (SJF) scheduling algorithm, or the highest response ratio first (RTR) scheduling algorithm is used to determine the processing order of the task scheduling packets. An ordered processing relationship is established between the task scheduling packets and the idle computing nodes on the online computing node list. The IP address of the computing node computer that processes the task scheduling packet is bound to the task scheduling packet, and the feedback is sent to the master control node computer via the TCP communication protocol.
[0044] Preferably, the communication protocol between the compute node computer and the master node computer includes:
[0045] (a) Main control node computer:
[0046] 1.1) The master control node computer connects to the computing node computer via IP and a specified port. If the connection fails, it will reconnect after a delay of T1. If the reconnection fails 3 times, it will return to request task scheduling again.
[0047] 1.2) After a successful connection, package the task and send it to the compute node computer;
[0048] 1.3) Receive the running progress packet from the computing node computer and update the task execution progress;
[0049] 1.4) If no progress packet is received for three consecutive times, the task execution will be terminated and the task will be rescheduled from the coordinator.
[0050] 1.5) Receive the task execution result packet and disconnect.
[0051] (ii) Computing node computer side:
[0052] 2.1) After the compute node computer starts up, it waits for a connection on the designated port;
[0053] 2.2) After accepting the connection, continue accepting task packets;
[0054] 2.3) Execute the task on the local machine and send the percentage of task execution to the master node computer every time interval T1;
[0055] 2.4) After the task is completed, send the task results to the master node computer and disconnect after completion.
[0056] Generate communication messages using the UDP or TCP protocol, specifically including:
[0057] Define the message format file, with proto as the file extension;
[0058] Use compilers specified for different needs to generate code files, which are in .h or .cc format;
[0059] Use the APIs provided by the Protocol library to write application protocol functions.
[0060] Preferably, the time T1 = 5s and T2 = 15s.
[0061] Based on the Modelica distributed simulation system, it includes a simulation module, a distributed scheduling module, a master node, and computing nodes.
[0062] The simulation module allows you to choose between offline and real-time simulation. Offline simulation waits for the simulation to compile and generate an executable (.exe) file, which is then run to obtain and display the simulation results. Real-time simulation outputs the results of each simulation iteration. It utilizes inter-process communication to acquire the simulation model's output, perform variable analysis and segmentation, and then output the results as the real-time results for each iteration. The simulation model execution process involves multiple iterations, and the actual execution time of each iteration depends on the complexity of the simulation model and the performance of the computer used for simulation. When displaying real-time simulation results, the horizontal axis is the time axis. This time represents the internal parameters of the simulation model and requires time conversion before being synchronized to the display interface in real time.
[0063] The distributed scheduling module includes functions such as distributed coordination and task scheduling.
[0064] Distributed coordination: The distributed coordinator tracks the status of computing nodes. The status information of computing nodes includes whether the computing node is idle, CPU usage, memory resource usage, online time, number of completed tasks, etc., and then provides a computing node status information table to the master node. After a computing node comes online, it will not only be tracked by the distributed scheduling module, but the distributed scheduling module will also update the computing node status information table periodically. When a computing node goes offline, it will be deleted from the list of online computing nodes.
[0065] Task Scheduling: The master node sends task scheduling packets to the distributed coordinator. It can process these packets according to the selected scheduling algorithm, such as First-Come, First-Served (FCFS), Shortest Job First (SJF), or Highest Response Ratio First (HRRF) algorithm. The processing order of the task scheduling packets is determined by establishing an ordered mapping between the task scheduling packets and available computing nodes on the online computing node list. The IP address of the computing node processing the task scheduling packet is bound to the task scheduling packet, and feedback is sent back to the master node via TCP communication protocol. A task queue records the task status, including pending, executing, and completed states. Tasks that time out or encounter node errors are reassigned.
[0066] Master Node: The master node computer acts as a simulation platform node, operating in two main ways: When there are no task scheduling tasks, the master node computer initiates a process by requesting information from the distributed coordinator about the status of the compute nodes. When there are task scheduling tasks, it sends a task scheduling packet to the distributed coordinator, which schedules the corresponding compute node. The master node then receives the task execution result packets from the compute nodes, reads and stores the data, and continues to distribute tasks and perform simulations. If the current simulation mode is offline simulation, the master node waits until the simulation ends, runs the executable file generated by the simulation, and displays the output results of the simulation model through the simulation window. If the current simulation mode is real-time simulation, the master node computer processes the obtained data and then displays it to the user through the real-time simulation window.
[0067] Compute Node: A compute node computer is a compute node located on the same computer or local area network as the master node computer. After starting up, the compute node computer connects to the distributed coordinator via the UDP communication protocol, then sends heartbeat packets indicating CPU and memory usage to the distributed coordinator, signifying that the compute node computer is online and waiting for the master node computer to connect and assign tasks. After connecting to the master node computer, it sends the percentage of task execution to the master node computer every time interval T1. After task execution is complete, it sends the task results back to the master node computer and then disconnects.
[0068] Compared with the prior art, the beneficial effects of the present invention include:
[0069] 1) Improved simulation efficiency. This invention implements distributed simulation computing for Modelica, suitable for simulation computing of large and complex simulation models. It distributes computing tasks to computing node computers on a local area network, reducing the execution time of simulation computing tasks on the master node and improving simulation efficiency.
[0070] 2) Flexible structure. This invention does not employ remote procedure call technology. Only a minimal communication module and execution container need to be installed on the distributed computing node computers. Tasks can run as soon as the computing nodes come online, and the offline system automatically redistributes tasks to other computing nodes. The more computing nodes online, the higher the quality of the computing service.
[0071] 3) Lightweight design. The state of the computing nodes is tracked and recorded by the distributed coordinator. When there are no scheduled tasks, the simulation platform, acting as the master node, requires no additional overhead. When task scheduling is needed, the coordinator only needs to recommend computing nodes based on the scheduling algorithm; subsequent task distribution and result feedback are handled directly by the master node and the computing nodes. This reduces the waste of bandwidth and processor resources caused by forwarding by distributed nodes.
[0072] 4) Good adaptability. Using components as the scheduling unit for distributed simulation, it adapts to the working mode of the Modelica simulation platform, which uses simulation components for configuration modeling.
[0073] 5) Advantages of the communication protocol. The custom communication protocol defined by the Protocol library improves communication performance, efficiency, and memory overhead between the compute nodes, distributed coordinator, and master node in the Modelica distributed simulation system. It also supports backward and forward compatibility and offers good scalability. The unique advantage of combining UDP and TCP protocols: UDP is a connectionless transport protocol that provides applications with a way to send encapsulated IP packets without establishing a connection. This method allows the distributed coordinator's IP packets to be encapsulated and sent to the master node and compute nodes, eliminating the need to establish a connection based on IP addresses. After obtaining the distributed coordinator's IP address via UDP, TCP is used to establish the connection. This combination of the two communication protocols ensures that nodes in different modules can connect and communicate normally, regardless of their location on the same local area network. Attached Figure Description
[0074] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0075] Figure 1 This is a flowchart of a distributed simulation method according to an embodiment of the present invention.
[0076] Figure 2 This is an architecture diagram of the distributed simulation system according to an embodiment of the present invention.
[0077] Figure 3 This is a distributed simulation effect diagram of Example 1.
[0078] Figure 4 This is a distributed simulation effect diagram of Example 2.
[0079] Figure 5 This is an interface diagram of the distributed simulation system in Example 3. Detailed Implementation
[0080] Example 1
[0081] like Figure 1-2 As shown, the distributed simulation method for Modelica includes the following steps:
[0082] Step 1: First, compile the functions written in C / C++ and Fortran into dynamic libraries, and then encapsulate the dynamic libraries into components that can be used on the Modelica platform;
[0083] Step 2: Use the components mentioned above to build a simulation model in the Modelica simulation platform, set whether to enable distributed, offline, online and other simulation modes, as well as simulation parameters such as simulation step size and variables, and compile to generate the simulation system;
[0084] Step 3: In distributed simulation mode, when the master node executes the simulation system, it will schedule tasks on a component-by-component basis, generate configuration files and simulation data from the parameters of the dynamic library functions, and package the configuration files, dynamic libraries, and simulation data.
[0085] Step 4: The master node requests task scheduling from the distributed coordinator. The distributed coordinator can start at this time, or it can start in or before step 3. The steps after the distributed coordinator starts are as follows:
[0086] Step 4.1: Start the distributed coordinator and broadcast the IP address to the compute node computer and the master node computer via the UDP communication protocol;
[0087] Step 4.2: After obtaining the IP address of the distributed coordinator via the UDP communication protocol, the computing node computer connects to the distributed coordinator;
[0088] Step 4.3: After the computing node computer connects to the distributed coordinator, it sends its status information, such as CPU and memory status, to the distributed coordinator. Idle computing nodes wait for the master node to connect and send task packets.
[0089] Step 4.4: After obtaining the IP address of the distributed coordinator through the UDP communication protocol, the master node computer connects to the distributed coordinator;
[0090] Step 4.5: The master control node computer periodically requests the status list of currently online computing node computers from the distributed coordinator. When there is a computing task, it sends a request task scheduling packet to the distributed coordinator. The coordinator sends the recommended IP address of the computing node computer to the master control node computer according to the scheduling algorithm, and the master control node computer connects to the computing node computer.
[0091] Step 4.6: The master node computer sends a task package to the compute node computer. After receiving the task package containing the configuration file, simulation data, and dynamic library, the compute node computer starts the executor and executes the function in the dynamic library according to the configuration file, with the received simulation data as the input parameter. After the execution is completed, the output result is sent back to the master node.
[0092] Every 5 seconds, the compute node computer sends the percentage of task execution to the master node computer. If the master node computer client does not receive the progress packet within 15 seconds, it terminates the task execution and re-requests task scheduling from the distributed coordinator.
[0093] Step 4.7: The master control node computer receives the running progress packet from the compute node computer, updates the task execution progress, and continues until it receives the task execution result packet, then disconnects.
[0094] Step 4.8: After receiving the data from the compute node computer, the master node computer reads and stores the data, and then continues to distribute tasks and simulations. The master node computer processes the data and then displays it to the user through the simulation window.
[0095] The communication protocol between the distributed coordinator and the computing node computers specifically includes:
[0096] (a) Computing node computer side:
[0097] 1.1) After the compute node computer starts up, it uses the UDP protocol to broadcast a request for the coordinator's IP address to the local area network; if the IP address acquisition fails, it resends the UDP request packet every 5 seconds until it is successfully acquired;
[0098] 1.2) After the computing node computer obtains the coordinator's IP address, it establishes a TCP connection on the specified port and sends a heartbeat packet containing CPU and memory usage information to the coordinator every 5 seconds.
[0099] (ii) Distributed Coordinator Side:
[0100] 2.1) After the distributed coordinator starts, it enters a connection-waiting state on the designated port; at the same time, it listens for UDP packets.
[0101] 2.2) Upon receiving a UDP request for an IP address, a response packet is sent to return the local machine's IP address;
[0102] 2.3) Upon receiving a connection request from a computing node computer on the specified port, a TCP connection is established;
[0103] 2.4) If a heartbeat packet is received from a compute node computer, the compute node status is recorded in the online list. If no heartbeat packet is received from a compute node for three consecutive times, the compute node is deleted from the online list.
[0104] The communication protocol between the distributed coordinator and the master node computer includes:
[0105] (a) Main control node computer:
[0106] 1.1) After the master node computer starts up, it uses the UDP protocol to broadcast a request for the coordinator's IP address to the local area network; if the IP address acquisition fails, it resends the UDP request packet every 5 seconds until it is successfully acquired;
[0107] 1.2) After obtaining the IP address, the master node computer acts as a client to connect to the coordinator via the IP address and the specified port number; if the connection fails, it will automatically reconnect to the coordinator after 5 seconds.
[0108] 1.3) After a successful connection, the master node computer requests the list of currently online computing nodes and the status of CPU and memory from the coordinator every 15 seconds for display on the simulation platform;
[0109] 1.4) When the master node computer has a computing task, it sends a task scheduling request packet to the coordinator;
[0110] 1.5) After receiving the request scheduling response packet, the master control node computer starts communication with the computing node computer through the IP address of the computing node computer provided in the response packet; if the communication between the master control node computer and the computing node computer fails, it will return to step 1.4) to request scheduling again.
[0111] (ii) Distributed Coordinator Side:
[0112] 2.1) After the distributed coordinator starts, it enters a connection-waiting state on the designated port; at the same time, it listens for UDP packets.
[0113] 2.2) Upon receiving a UDP request for an IP address, a response packet is sent to return the local machine's IP address;
[0114] 2.3) Upon receiving a connection request from a client on the specified port on the master computer, a TCP connection is established;
[0115] 2.4) Upon receiving a request for an online computing node, return a list of online computing node computers;
[0116] 2.5) Upon receiving a request task scheduling packet, select one of the following scheduling algorithms to process the task scheduling packet: First-Come, First-Served (FCFS), Shortest Job First (SJF), or Highest Response Ratio First (HRRR). After processing the ordered task scheduling packet, assign it to an idle computing node in the online computing node list, bind its IP address to the task scheduling packet, and send it back to the master node computer via TCP communication protocol.
[0117] The communication protocols between the compute node computer and the master node computer include:
[0118] (a) Main control node computer:
[0119] 1.1) The master control node computer connects to the computing node computer via IP and a specified port. If the connection fails, it will be delayed for 5 seconds before reconnecting. If the connection fails 3 times, it will return to request task scheduling again.
[0120] 1.2) After a successful connection, package the task and send it to the compute node computer;
[0121] 1.3) Receive the running progress packet from the computing node computer and update the task execution progress;
[0122] 1.4) If no progress packet is received for three consecutive times, the task execution will be terminated and the task will be rescheduled from the coordinator.
[0123] 1.5) Receive the task execution result packet and disconnect.
[0124] (ii) Computing node computer side:
[0125] 2.1) After the compute node computer starts up, it waits for a connection on the designated port;
[0126] 2.2) After accepting the connection, continue accepting task packets;
[0127] 2.3) Execute the task on the local machine and send the task execution percentage to the master node computer every 5 seconds;
[0128] 2.4) After the task is completed, send the task results to the master node computer and disconnect after completion.
[0129] In this embodiment, generating communication messages using the UDP or TCP protocol specifically includes:
[0130] Define the message format file, with proto as the file extension;
[0131] Use compilers specified for different needs to generate code files, which are in .h or .cc format;
[0132] Use the APIs provided by the Protocol library to write applications.
[0133] In this embodiment, dynamic libraries and runtime data are used as the scheduling units for distributed scheduling. That is, the task package distributed from the master control node computer to the computing node computer by the distributed coordinator includes dynamic libraries and runtime data.
[0134] In this embodiment, the encapsulation method of the dynamic library refers to the function encapsulation method disclosed in Chinese Invention Patent No. CN113220309B, "Multilingual Modelica Component Batch Generation System and Method".
[0135] The simulation effect of the embodiment is as follows Figure 3 As shown.
[0136] Example 2
[0137] like Figure 1-2 As shown, the distributed simulation method for Modelica includes the following steps:
[0138] Step 1: Compile the functions written in C / C++ and Fortran into dynamic libraries, and encapsulate the dynamic libraries into components that can be used on the Modelica platform;
[0139] Step 2: Use components in the Modelica simulation platform to build a simulation model, set whether to enable distributed, offline, and online simulation modes, as well as the simulation step size and variables, and compile to generate the simulation program;
[0140] Step 3: In distributed simulation mode, when the master node executes the simulation program, it schedules tasks on a component-by-component basis, generates configuration files and simulation data from the parameters of the dynamic library functions, and packages the configuration files, dynamic libraries, and simulation data.
[0141] Step 4: The master node requests task scheduling from the distributed coordinator. After receiving the task scheduling request, the distributed coordinator recommends computing nodes according to the scheduling algorithm and distributes the task package to the computing nodes. After the computing nodes execute the distributed computing tasks, they send the execution results back to the master node, and the master node summarizes the results.
[0142] Step 4.1: Start the distributed coordinator and broadcast the IP address to the compute node computer and the master node computer via the UDP communication protocol;
[0143] Step 4.2: After obtaining the IP address of the distributed coordinator via the UDP communication protocol, the computing node computer connects to the distributed coordinator;
[0144] Step 4.3: After the computing node computer connects to the distributed coordinator, it sends its status information, such as CPU and memory status, to the distributed coordinator. Idle computing nodes wait for the master node to connect and send task packets.
[0145] Step 4.4: After obtaining the IP address of the distributed coordinator through the UDP communication protocol, the master node computer connects to the distributed coordinator;
[0146] Step 4.5: The master control node computer periodically requests the status list of currently online computing node computers from the distributed coordinator. When there is a computing task, it sends a request task scheduling packet to the distributed coordinator to obtain the IP address of the online computing node computer and connect to the computing node computer.
[0147] Step 4.6: The master node computer sends a task package to the compute node computer. After receiving the task package containing the configuration file, simulation data, and dynamic library, the compute node computer starts the executor and executes the function in the dynamic library according to the configuration file, with the received simulation data as the input parameter. After the execution is completed, the output result is sent back to the master node.
[0148] Every 5 seconds, the compute node computer sends the percentage of task execution to the master node computer. If the master node computer client does not receive the progress packet within 15 seconds, it terminates the task execution and re-requests task scheduling from the distributed coordinator.
[0149] Step 4.7: The master control node computer receives the running progress packet from the compute node computer, updates the task execution progress, and continues until it receives the task execution result packet, then disconnects.
[0150] Step 4.8: The master control node computer receives the task execution result packet from the computing node computer. The master control node computer processes the obtained result data and then displays it to the user through the real-time simulation window.
[0151] The communication protocol in Example 2 is the same as that in Example 1.
[0152] The simulation effect of the embodiment is as follows Figure 4 As shown.
[0153] The implementation extends Modelica's real-time simulation capabilities by iteratively processing the simulation results of each round, acquiring the simulation output in real time, understanding the changes in simulation variables, and terminating the simulation early as needed, making the simulation process more flexible and avoiding unnecessary time wastage.
[0154] Example 3
[0155] A distributed simulation system for Modelica includes a simulation module, a distributed scheduling module, a master node, and computing nodes.
[0156] The simulation module allows you to choose between offline and real-time simulation. Offline simulation waits for the simulation to compile and generate an executable (.exe) file, which is then run to obtain and display the simulation results. Real-time simulation outputs the results of each simulation iteration. It utilizes inter-process communication to acquire the simulation model's output, perform variable analysis and segmentation, and then output the results as the real-time results for each iteration. The simulation model execution process involves multiple iterations, and the actual execution time of each iteration depends on the complexity of the simulation model and the performance of the computer used for simulation. When displaying real-time simulation results, the horizontal axis is the time axis. This time represents the internal parameters of the simulation model and requires time conversion before being synchronized to the display interface in real time.
[0157] The distributed scheduling module includes functions such as distributed coordination and task scheduling.
[0158] Distributed coordination: The distributed coordinator tracks the status of computing nodes. The status information of computing nodes includes whether the computing node is idle, CPU usage, memory resource usage, online time, number of completed tasks, etc., and then provides a computing node status information table to the master node. After a computing node comes online, it will not only be tracked by the distributed scheduling module, but the distributed scheduling module will also update the computing node status information table periodically. When a computing node goes offline, it will be deleted from the computing node status information table.
[0159] Task Scheduling: The master node sends task scheduling packets to the distributed coordinator, which can process them according to a selected scheduling algorithm, such as First-Come, First-Served (FCFS), Shortest Job First (SJF), or Highest Response Ratio First (HRRF). After processing and ordering the task scheduling packets, a mapping is established between the ordered task scheduling packets and available computing nodes in the online computing node list. The IP address of the computing node processing the task scheduling packet is bound to the task scheduling packet. A task queue records the task status, including pending, executing, and completed states. Tasks that time out or encounter node errors are reassigned.
[0160] Master Node: The master node computer acts as a simulation platform node, operating in two main ways: When there are no task scheduling tasks, the master node computer initiates a process by requesting information from the distributed coordinator about the status of the compute nodes. When there are task scheduling tasks, it sends a task scheduling packet to the distributed coordinator, which schedules the corresponding compute node. The master node then receives the task execution result packets from the compute nodes, reads and stores the data, and continues to distribute tasks and perform simulations. If the current simulation mode is offline simulation, the master node waits until the simulation ends, runs the executable file generated by the simulation, and displays the output results of the simulation model through the simulation window. If the current simulation mode is real-time simulation, the master node computer processes the obtained data and then displays it to the user through the real-time simulation window.
[0161] Compute Node: A compute node computer is a compute node located on the same computer or local area network as the master node computer. After starting up, the compute node computer connects to the distributed coordinator via the UDP communication protocol. It then sends heartbeat packets to the distributed coordinator indicating that it is online and waiting for the master node computer to connect and assign tasks. After connecting with the master node computer, it sends the percentage of task execution to the master node computer every time interval T1. After the task is completed, it sends the task result back to the master node computer and then disconnects.
[0162] The interface of the distributed simulation system in the embodiment is as follows: Figure 5 As shown.
[0163] The distributed simulation system in Example 3 adopts the distributed simulation method in Example 2.
Claims
1. A distributed simulation method for Modelica, characterized in that, The simulation system of the method includes a master control node computer, a distributed coordinator, computing node computers, and executors running on the computing node computers. The method uses components as scheduling units. During distributed simulation, the components distributed to the node computers for execution are Modelica components, which are encapsulated from dynamic library functions. During simulation, the distributed coordinator recommends computing nodes according to the scheduling algorithm. The simulation platform allocates the execution tasks, consisting of configuration files, task data, and task dynamic libraries, to distributed computing nodes on the local area network for execution. After execution, the distributed computing nodes send the execution results back to the master control node. The master control node summarizes the results to complete the simulation, realizing the distributed parallel execution of simulation tasks and improving simulation performance. The method includes the following steps: Step 1: Compile the functions written in C / C++ and Fortran into dynamic libraries, and encapsulate the dynamic libraries into components that can be used on the Modelica simulation platform; Step 2: Use components in the Modelica simulation platform to build a simulation model, set whether to enable distributed, offline or online simulation mode, simulation step size, simulation variables, and compile to generate the simulation program; Step 3: In distributed simulation mode, when the master node executes the simulation program, it schedules tasks on a component-by-component basis, generates configuration files and simulation data from the parameters of the dynamic library functions, and packages the configuration files, dynamic libraries, and simulation data. Step 4: The master node requests task scheduling from the distributed coordinator. After receiving the task scheduling request, the distributed coordinator recommends computing nodes according to the scheduling algorithm. The master node communicates with the computing nodes to complete the task package distribution. After receiving the task package, the computing node executes the computing task and sends the execution result back to the master node. The master node then summarizes the results. Step 4.1: After the distributed coordinator starts, it broadcasts its own IP address to the compute nodes and master node computers via the UDP protocol; Step 4.2: The compute node computer connects to the distributed coordinator based on the IP address of the distributed coordinator obtained from the UDP message; Step 4.3: After the computing node computer connects to the distributed coordinator, it sends its status information to the distributed coordinator. The computing node connected to the distributed coordinator waits for the master node to connect on the preset port. Step 4.4: The master node computer connects to the distributed coordinator based on the IP address of the distributed coordinator obtained through UDP communication; Step 4.5: The master control node computer periodically requests the status list of currently online computing node computers from the distributed coordinator. When there is a computing task, it sends a request task scheduling packet to the distributed coordinator. The coordinator sends the recommended IP address of the computing node computer to the master control node computer according to the scheduling algorithm, and the master control node computer connects to the computing node computer. Step 4.6: The master control node computer sends a task package to the compute node computer. After receiving the task package, the compute node computer sends the percentage of task execution to the master control node computer every time T1. If the master control node computer client does not receive the progress package within time T2, it terminates the task execution and re-requests task scheduling from the distributed coordinator. Step 4.7: The master control node computer receives the running progress packet from the compute node computer, updates the task execution progress, and continues until it receives the task execution result packet, then disconnects. Step 4.8: The master control node computer receives the task execution result packet from the computing node computer, summarizes and uses the results, and completes the subsequent simulation.
2. The distributed simulation method for Modelica according to claim 1, characterized in that, The communication protocol between the distributed coordinator and the computing node computers specifically includes: (a) Computing node computer side: 1.1) After the compute node computer starts up, it uses the UDP communication protocol to broadcast a request for the coordinator's IP address to the local area network; if the compute node computer fails to obtain the IP address, it resends the UDP request packet every time interval T1 until it obtains the IP address successfully. 1.2) After the computing node computer obtains the coordinator's IP address, it establishes a TCP connection on the specified port and sends a heartbeat packet containing CPU and memory usage information to the coordinator every time T1. (ii) Distributed Coordinator Side: 2.1) After the distributed coordinator starts, it enters a connection-waiting state on the designated port; at the same time, it listens for UDP protocol packets. 2.2) Upon receiving a UDP packet from the compute node requesting an IP address, send a response packet to return the local IP address; 2.3) Upon receiving a connection request from a computing node computer on the specified port, a TCP connection is established; 2.4) If a heartbeat packet is received from a compute node computer, the status of the compute node computer is recorded in the online list. If no heartbeat packet is received from a compute node computer for three consecutive times, the compute node computer is deleted from the online list.
3. The distributed simulation method for Modelica according to claim 2, characterized in that, The communication protocol between the distributed coordinator and the master node computer includes: (a) Main control node computer: 1.1) After the master control node computer starts up, it uses the UDP protocol to broadcast a request for the IP address of the distributed coordinator to the local area network; if the master control node computer fails to obtain the IP address, it resends the UDP request packet every time T1 until it obtains the IP address successfully. 1.2) After obtaining the IP address, the master control node computer connects to the distributed coordinator through the IP address and the specified port number; if the master control node computer fails to connect to the distributed coordinator, it automatically reconnects to the distributed coordinator every time interval T1. 1.3) After a successful connection, the master control node computer requests the list of currently online computing node computers and the status of CPU and memory from the distributed coordinator every time interval T2; 1.4) When the master node computer has a computing task, it sends a request task scheduling packet to the distributed coordinator; 1.5) After receiving the response packet of the request task scheduling packet, the master control node computer starts communication with the computing node computer through the IP address of the computing node computer provided in the response packet; If communication between the master control node computer and the compute node computer fails, return to step 1.4) to request scheduling again; (ii) Distributed Coordinator Side: 2.1) After the distributed coordinator starts, it enters a connection-waiting state on the designated port; at the same time, it listens for UDP protocol packets. 2.2) Upon receiving a UDP packet from the master node computer requesting an IP address, send a response packet to return the local IP address; 2.3) Upon receiving a connection request from a client on the specified port on the master computer, a TCP connection is established; 2.4) Upon receiving a request from an online computing node, return a list of online computing node computers; 2.5) Upon receiving a request task scheduling packet, the first-come, first-served scheduling algorithm, the shortest job first scheduling algorithm, or the highest response ratio first scheduling algorithm are used to determine the processing order of the task packets. An ordered processing relationship is established between the task packets and the idle computing nodes on the online computing node list. The IP address of the computing node computer that processes the task packet is bound to the task packet, and feedback is sent to the master node computer through the TCP communication protocol.
4. The distributed simulation method for Modelica according to claim 3, characterized in that, The communication protocols between the compute node computer and the master node computer include: (a) Main control node computer: 1.1) The master control node computer connects to the computing node computer via IP and a specified port. If the connection fails, it will reconnect after an interval of T1. If the reconnection fails 3 times, it will return to request task scheduling again. 1.2) After a successful connection, package the task and send it to the compute node computer; 1.3) Receive the running progress packet from the computing node computer and update the task execution progress; 1.4) If no progress packet is received for three consecutive times, the task execution will be terminated, and the task will be rescheduled from the distributed coordinator. 1.5) Receive the task execution result packet and disconnect; (ii) Computing node computer side: 2.1) After the compute node computer starts up, it waits for a connection on the designated port; 2.2) After connecting to the master control node computer, continue to receive task scheduling packets; 2.3) Execute the task on the local machine and send the percentage of task execution to the master node computer every time interval T1; 2.4) After the task is completed, send the task results to the master node computer and disconnect after completion.
5. The distributed simulation method for Modelica according to claim 2, 3, or 4, characterized in that, Generate communication messages using the UDP or TCP protocol, specifically including: Define the message format file, with proto as the file extension; Use compilers specified for different needs to generate code files, which are in .h or .cc format; Use the APIs provided by the Protocol library to write application protocol functions.
6. The distributed simulation method for Modelica according to claim 5, characterized in that, In step 4, after receiving the task containing the configuration file, simulation data, and dynamic library, the compute node computer starts the executor and executes the function in the dynamic library according to the configuration file, with the received simulation data as the input parameter; after the execution is completed, the output result is sent back to the master node.
Citation Information
Patent Citations
Multilingual Modelica Component Batch Generation System and Method
CN113220309B