[go: up one dir, main page]

CN101571810B - Method for implementing program, method for verifying program result, devices and system - Google Patents

Method for implementing program, method for verifying program result, devices and system Download PDF

Info

Publication number
CN101571810B
CN101571810B CN2009100863378A CN200910086337A CN101571810B CN 101571810 B CN101571810 B CN 101571810B CN 2009100863378 A CN2009100863378 A CN 2009100863378A CN 200910086337 A CN200910086337 A CN 200910086337A CN 101571810 B CN101571810 B CN 101571810B
Authority
CN
China
Prior art keywords
node
program
pointer
nodes
instruction
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN2009100863378A
Other languages
Chinese (zh)
Other versions
CN101571810A (en
Inventor
徐华
温赟
杨甲东
万伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tsinghua University
Original Assignee
Tsinghua University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tsinghua University filed Critical Tsinghua University
Priority to CN2009100863378A priority Critical patent/CN101571810B/en
Publication of CN101571810A publication Critical patent/CN101571810A/en
Application granted granted Critical
Publication of CN101571810B publication Critical patent/CN101571810B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

本发明公开了执行程序的方法、验证程序结果的方法、装置及系统,属于计算机领域。执行程序的方法包括:从源程序的文本文件中,获取指令信息;根据所述指令信息,建立串行队列;根据所述串行队列,构造并行时序图;根据所述并行时序图,并行执行所述源程序。执行程序的装置包括:获取模块、建立模块、构造模块和执行模块。验证程序结果的装置包括:创建模块、第一设置模块、第二设置模块、映射模块、第一判断模块和第二判断模块。执行程序的系统包括:执行程序的装置和验证程序结果的装置。本发明能够提高开发程序的效率、方便调度和部署程序。

Figure 200910086337

The invention discloses a method for executing a program, a method for verifying a program result, a device and a system, and belongs to the field of computers. The method for executing a program includes: obtaining instruction information from a text file of a source program; establishing a serial queue according to the instruction information; constructing a parallel timing diagram according to the serial queue; executing in parallel according to the parallel timing diagram the source program. The device for executing the program includes: an acquisition module, an establishment module, a construction module and an execution module. The device for verifying program results includes: a creation module, a first setting module, a second setting module, a mapping module, a first judging module and a second judging module. A system for executing a program includes means for executing the program and means for verifying the results of the program. The invention can improve the efficiency of developing programs and facilitate scheduling and deployment of programs.

Figure 200910086337

Description

执行程序的方法、验证程序结果的方法、装置及系统Method for executing program, method, device and system for verifying program result

技术领域technical field

本发明涉及计算机领域,特别涉及执行程序的方法、验证程序结果的方法、装置及系统。The invention relates to the computer field, in particular to a method for executing a program, a method, a device and a system for verifying the result of the program.

背景技术Background technique

PLC(Programmable Logic Controller,可编程逻辑控制器)采用一种循环扫描的执行方式。该方式分为三个阶段:输入采样、用户程序执行和投入运行。完成上述三个阶段称为一个扫描周期。其中,运行于PLC上的程序都是依照循环扫描的执行方式串行执行。PLC (Programmable Logic Controller, Programmable Logic Controller) adopts a cyclic scanning execution method. This method is divided into three phases: input sampling, user program execution and putting into operation. Completing the above three stages is called a scan cycle. Among them, the programs running on the PLC are serially executed in accordance with the execution mode of cyclic scanning.

由于PLC硬件对于扫描周期的时长都有一定限制,在执行相对复杂的控制功能时,采用串行执行程序的方法,无法在单个扫描周期中执行完整个程序,程序员必须将原本完整的程序分成多段,通过单独执行每段程序来完成该控制功能,或是在相互通信的多个PLC上分别编写程序,通过每个PLC执行自身的程序,协同完成该控制功能。Since the PLC hardware has a certain limit on the length of the scan cycle, when performing relatively complex control functions, the method of serially executing the program cannot execute the entire program in a single scan cycle, and the programmer must divide the original complete program into Multi-segment, the control function is completed by executing each segment of the program independently, or the program is written separately on multiple PLCs that communicate with each other, and each PLC executes its own program to cooperate to complete the control function.

在实现本发明的过程中,发明人发现现有技术至少存在以下问题:In the process of realizing the present invention, the inventor finds that there are at least the following problems in the prior art:

现有的串行执行程序的方法,在执行相对复杂的控制功能时,必须将完整的程序分成多段或分别编写在多个PLC上,极大地影响了程序员开发程序的效率,并给调试和部署程序带来不便。In the existing method of serially executing programs, when performing relatively complex control functions, the complete program must be divided into multiple sections or written on multiple PLCs, which greatly affects the efficiency of programmers in developing programs, and brings great difficulties for debugging and Deployment procedures are inconvenient.

发明内容Contents of the invention

为了使提高开发程序的效率,方便调试和部署程序,本发明实施例提供了执行程序的方法、验证执行结果的方法、装置及系统。所述技术方案如下:In order to improve the efficiency of program development and facilitate debugging and deployment of programs, the embodiments of the present invention provide a method for executing a program, a method, a device, and a system for verifying an execution result. Described technical scheme is as follows:

一种执行程序的方法,所述方法包括:A method of executing a program, the method comprising:

顺序扫描源程序的文本文件中的指令;Sequentially scan the instructions in the text file of the source program;

读取所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块;Read the name of the instruction, the operand of the instruction, the delimiter to which the instruction belongs, and the program block to which the instruction belongs;

计算所述定界符的执行时间;calculating the execution time of said delimiter;

获取所述操作数的存储空间和读写属性;Obtain the storage space and read/write attributes of the operand;

将所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块、所述定界符的执行时间、所述操作数的存储空间和读写属性作为指令信息;The name of the instruction, the operand of the instruction, the delimiter and the program block to which the instruction belongs, the execution time of the delimiter, the storage space of the operand and the read-write attribute are used as the instruction information;

建立串行队列;Create a serial queue;

从所述指令信息的程序块的主程序块为入口,顺序扫描所述指令信息中的定界符包括的指令;From the main program block of the program block of the instruction information as an entry, sequentially scan the instructions included in the delimiter in the instruction information;

将所述定界符作为节点加入到所述串行队列,其中,将所述定界符的执行时间作为所述节点的权重;adding the delimiter as a node to the serial queue, wherein the execution time of the delimiter is used as the weight of the node;

判断所述指令是否为调用CALL指令,如果所述指令为CALL指令,则跳入所述CALL指令调用的程序块,扫描所述程序块中的定界符包括的指令;Judging whether the instruction is to call a CALL instruction, if the instruction is a CALL instruction, then jump into the program block called by the CALL instruction, and scan the instructions included in the delimiter in the program block;

将所述串行队列中的节点存入并行时序图中;storing the nodes in the serial queue into a parallel sequence diagram;

在所述串行队列中,设置指针1指向队头节点,设置指针2指向所述指针1指向的节点的下一个节点;In the serial queue, the pointer 1 is set to point to the team head node, and the pointer 2 is set to point to the next node of the node pointed to by the pointer 1;

根据操作数的存储空间和读写属性,判断所述指针1指向的节点与所述指针2指向的节点是否存在数据依赖关系,如果存在,在所述并行时序图中,在所述指针1指向的节点与所述指针2指向的节点之间加入有向边,方向为所述指针1指向的节点指向所述指针2指向的节点,在所述串行队列中,重新设置所述指针2指向下一个节点;According to the storage space and the read-write attribute of the operand, it is judged whether there is a data dependency relationship between the node pointed to by the pointer 1 and the node pointed to by the pointer 2, and if there is, in the parallel sequence diagram, the node pointed by the pointer 1 A directed edge is added between the node pointed to by the pointer 2 and the node pointed to by the pointer 2, and the direction is that the node pointed to by the pointer 1 points to the node pointed to by the pointer 2, and in the serial queue, the pointer 2 points to next node;

如果不存在,在所述串行队列中,重新设置所述指针2指向下一个节点;If it does not exist, in the serial queue, reset the pointer 2 to point to the next node;

根据所述并行时序图,并行执行所述源程序;Executing the source program in parallel according to the parallel sequence diagram;

其中,所述源程序由一个或多个程序块组成,所述程序块由一个或多个定界符组成,所述定界符由一条或多条指令组成。Wherein, the source program is composed of one or more program blocks, the program block is composed of one or more delimiters, and the delimiter is composed of one or more instructions.

一种执行程序的装置,所述装置包括获取模块、建立模块、构造模块和执行模块:A device for executing a program, the device includes an acquisition module, an establishment module, a construction module and an execution module:

所述获取模块包括第一扫描单元、读取单元、计算单元和第一获取单元;The acquisition module includes a first scanning unit, a reading unit, a calculation unit and a first acquisition unit;

所述第一扫描单元,用于顺序扫描源程序的文本文件中的指令;The first scanning unit is used to sequentially scan the instructions in the text file of the source program;

所述读取单元,用于读取所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块;The reading unit is configured to read the name of the instruction, the operand of the instruction, the delimiter to which the instruction belongs, and the program block to which the instruction belongs;

所述计算单元,用于计算所述定界符的执行时间;The calculation unit is used to calculate the execution time of the delimiter;

所述第一获取单元,用于获取所述操作数的存储空间和读写属性;The first acquiring unit is configured to acquire the storage space and read/write attributes of the operand;

将所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块、所述定界符的执行时间、所述操作数的存储空间和读写属性作为指令信息;The name of the instruction, the operand of the instruction, the delimiter and the program block to which the instruction belongs, the execution time of the delimiter, the storage space of the operand and the read-write attribute are used as the instruction information;

所述建立模块包括建立单元、第二扫描单元、添加单元和判断单元;The building module includes a building unit, a second scanning unit, an adding unit and a judging unit;

所述建立单元,用于建立串行队列;The establishment unit is used to establish a serial queue;

所述第二扫描单元,用于从所述指令信息的程序块的主程序块为入口,顺序扫描所述指令信息中的定界符包括的指令;The second scanning unit is configured to sequentially scan the instructions included in the delimiter in the instruction information from the main program block of the instruction information program block as an entry;

所述添加单元,用于将所述定界符作为节点加入到所述串行队列,其中,将所述定界符的执行时间作为所述节点的权重;The adding unit is configured to add the delimiter as a node to the serial queue, wherein the execution time of the delimiter is used as the weight of the node;

所述判断单元,用于判断所述指令是否为调用CALL指令,如果所述指令为CALL指令,则跳入所述CALL指令调用的程序块,扫描所述程序块中的定界符包括的指令;The judging unit is used to judge whether the instruction is a call CALL instruction, if the instruction is a CALL instruction, then jump into the program block called by the CALL instruction, and scan the instructions included in the delimiter in the program block ;

所述构造模块包括存储单元、第一设置单元和第一判断单元;The construction module includes a storage unit, a first setting unit and a first judging unit;

所述存储单元,用于将所述串行队列中的节点存入并行时序图中;The storage unit is used to store the nodes in the serial queue into a parallel sequence diagram;

所述第一设置单元,用于在所述串行队列中,设置指针1指向队头节点,设置指针2指向所述指针1指向的节点的下一个节点;The first setting unit is configured to set the pointer 1 to point to the queue head node in the serial queue, and set the pointer 2 to point to the node next to the node pointed to by the pointer 1;

所述第一判断单元,用于根据操作数的存储空间和读写属性,判断所述指针1指向的节点与所述指针2指向的节点是否存在数据依赖关系,如果存在,在所述并行时序图中,在所述指针1指向的节点与所述指针2指向的节点之间加入有向边,方向为所述指针1指向的节点指向所述指针2指向的节点,在所述串行队列中,重新设置所述指针2指向下一个节点;如果不存在,在所述串行队列中,重新设置所述指针2指向下一个节点;The first judging unit is configured to judge whether there is a data dependency relationship between the node pointed to by the pointer 1 and the node pointed to by the pointer 2 according to the storage space and the read/write attribute of the operand, and if so, in the parallel sequence In the figure, a directed edge is added between the node pointed to by the pointer 1 and the node pointed to by the pointer 2, and the direction is that the node pointed to by the pointer 1 points to the node pointed to by the pointer 2, and in the serial queue , reset the pointer 2 to point to the next node; if it does not exist, reset the pointer 2 to point to the next node in the serial queue;

所述执行模块,用于根据所述并行时序图,并行执行所述源程序。The execution module is configured to execute the source program in parallel according to the parallel sequence diagram.

一种验证程序结果的方法,所述方法包括:A method of verifying program results, the method comprising:

根据并行时序图,创建Petri网模型;Create a Petri net model based on the parallel sequence diagram;

在所述Petri网模型中的第一个库节点中设置初始标志;Initial flag is set in the first storehouse node in described Petri net model;

设置指针指向程序执行序列中的第一个节点;Set the pointer to point to the first node in the program execution sequence;

将所述指针指向的节点映射到所述Petri网模型中对应的变迁节点;Mapping the node pointed by the pointer to the corresponding transition node in the Petri net model;

判断所述变迁节点的前库节点中是否存在所述初始标志,如果否,则返回程序结果出错的信息;Judging whether the initial flag exists in the front library node of the transition node, if not, returning the error message of the program result;

如果是,将所述初始标志移入所述变迁节点的后库节点,判断所述程序执行序列是否还存在其他的节点,如果是,设置所述指针指向下一个节点,如果否,返回程序结果正确的信息。If yes, move the initial flag into the back library node of the transition node, judge whether there are other nodes in the program execution sequence, if yes, set the pointer to point to the next node, if not, return the program result is correct Information.

一种验证程序结果的装置,所述装置包括:An apparatus for verifying program results, the apparatus comprising:

创建模块,用于根据并行时序图,创建Petri网模型;Create a module for creating a Petri net model based on a parallel sequence diagram;

第一设置模块,用于在所述Petri网模型中的第一个库节点中设置初始标志;The first setting module is used to set the initial sign in the first library node in the Petri net model;

第二设置模块,用于设置指针指向程序执行序列的第一个节点;The second setting module is used to set the pointer to point to the first node of the program execution sequence;

映射模块,用于将所述指针指向的节点映射到所述Petri网模型中对应的变迁节点;A mapping module, configured to map the node pointed to by the pointer to the corresponding transition node in the Petri net model;

第一判断模块,用于判断所述变迁节点的前库节点中是否存在所述初始标志,如果否,则返回程序结果出错的信息;The first judging module is used to judge whether the initial flag exists in the front library node of the transition node, and if not, return the information that the program result is wrong;

第二判断模块,用于当所述第一判断模块判断的结果为是,将所述初始标志移入所述变迁节点的后库节点,判断所述程序执行序列是否还存在其他的节点,如果是,设置所述指针指向下一个节点,如果否,返回程序结果正确的信息。The second judging module is used to move the initial flag into the back library node of the transition node when the judging result of the first judging module is yes, and judge whether there are other nodes in the program execution sequence, if yes , set the pointer to point to the next node, if not, return the information that the program result is correct.

一种执行程序的系统,所述系统包括执行程序的装置和验证程序结果的装置:A system for executing a program, the system comprising means for executing the program and means for verifying the results of the program:

所述执行程序的装置包括获取模块、建立模块、构造模块和执行模块;The device for executing the program includes an acquisition module, an establishment module, a construction module and an execution module;

所述获取模块包括第一扫描单元、读取单元、计算单元和第一获取单元;The acquisition module includes a first scanning unit, a reading unit, a calculation unit and a first acquisition unit;

所述第一扫描单元,用于顺序扫描源程序的文本文件中的指令;The first scanning unit is used to sequentially scan the instructions in the text file of the source program;

所述读取单元,用于读取所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块;The reading unit is configured to read the name of the instruction, the operand of the instruction, the delimiter to which the instruction belongs, and the program block to which the instruction belongs;

所述计算单元,用于计算所述定界符的执行时间;The calculation unit is used to calculate the execution time of the delimiter;

所述第一获取单元,用于获取所述操作数的存储空间和读写属性;The first acquiring unit is configured to acquire the storage space and read/write attributes of the operand;

将所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块、所述定界符的执行时间、所述操作数的存储空间和读写属性作为指令信息;The name of the instruction, the operand of the instruction, the delimiter and the program block to which the instruction belongs, the execution time of the delimiter, the storage space of the operand and the read-write attribute are used as the instruction information;

所述建立模块包括建立单元、第二扫描单元、添加单元和判断单元;The building module includes a building unit, a second scanning unit, an adding unit and a judging unit;

所述建立单元,用于建立串行队列;The establishment unit is used to establish a serial queue;

所述第二扫描单元,用于从所述指令信息的程序块的主程序块为入口,顺序扫描所述指令信息中的定界符包括的指令;The second scanning unit is configured to sequentially scan the instructions included in the delimiter in the instruction information from the main program block of the instruction information program block as an entry;

所述添加单元,用于将所述定界符作为节点加入到所述串行队列,其中,将所述定界符的执行时间作为所述节点的权重;The adding unit is configured to add the delimiter as a node to the serial queue, wherein the execution time of the delimiter is used as the weight of the node;

所述判断单元,用于判断所述指令是否为调用CALL指令,如果所述指令为CALL指令,则跳入所述CALL指令调用的程序块,扫描所述程序块中的定界符包括的指令;The judging unit is used to judge whether the instruction is a call CALL instruction, if the instruction is a CALL instruction, then jump into the program block called by the CALL instruction, and scan the instructions included in the delimiter in the program block ;

所述构造模块包括存储单元、第一设置单元和第一判断单元;The construction module includes a storage unit, a first setting unit and a first judging unit;

所述存储单元,用于将所述串行队列中的节点存入并行时序图中;The storage unit is used to store the nodes in the serial queue into a parallel sequence diagram;

所述第一设置单元,用于在所述串行队列中,设置指针1指向队头节点,设置指针2指向所述指针1指向的节点的下一个节点;The first setting unit is configured to set the pointer 1 to point to the queue head node in the serial queue, and set the pointer 2 to point to the node next to the node pointed to by the pointer 1;

所述第一判断单元,用于根据操作数的存储空间和读写属性,判断所述指针1指向的节点与所述指针2指向的节点是否存在数据依赖关系,如果存在,在所述并行时序图中,在所述指针1指向的节点与所述指针2指向的节点之间加入有向边,方向为所述指针1指向的节点指向所述指针2指向的节点,在所述串行队列中,重新设置所述指针2指向下一个节点;如果不存在,在所述串行队列中,重新设置所述指针2指向下一个节点;The first judging unit is configured to judge whether there is a data dependency relationship between the node pointed to by the pointer 1 and the node pointed to by the pointer 2 according to the storage space and the read/write attribute of the operand, and if so, in the parallel sequence In the figure, a directed edge is added between the node pointed to by the pointer 1 and the node pointed to by the pointer 2, and the direction is that the node pointed to by the pointer 1 points to the node pointed to by the pointer 2, and in the serial queue , reset the pointer 2 to point to the next node; if it does not exist, reset the pointer 2 to point to the next node in the serial queue;

所述执行模块,用于根据所述并行时序图,并行执行所述源程序;The execution module is configured to execute the source program in parallel according to the parallel sequence diagram;

其中,所述源程序由一个或多个程序块组成,所述程序块由一个或多个定界符组成,所述定界符由一条或多条指令组成;Wherein, the source program is composed of one or more program blocks, the program block is composed of one or more delimiters, and the delimiter is composed of one or more instructions;

所述验证程序结果的装置包括创建模块、第一设置模块、第二设置模块、映射模块、第一判断模块和第二判断模块;The device for verifying program results includes a creation module, a first setting module, a second setting module, a mapping module, a first judging module and a second judging module;

所述创建模块,用于根据并行时序图,创建Petri网模型;The creation module is used to create a Petri net model according to the parallel sequence diagram;

所述第一设置模块,用于在所述Petri网模型中的第一个库节点中设置初始标志;The first setting module is used to set an initial flag in the first library node in the Petri net model;

所述第二设置模块,用于设置指针指向程序执行序列的第一个节点;The second setting module is used to set the pointer to point to the first node of the program execution sequence;

所述映射模块,用于将所述指针指向的节点映射到所述Petri网模型中对应的变迁节点;The mapping module is configured to map the node pointed by the pointer to the corresponding transition node in the Petri net model;

所述第一判断模块,用于判断所述变迁节点的前库节点中是否存在所述初始标志,如果否,则返回程序结果出错的信息;The first judging module is used to judge whether the initial flag exists in the front library node of the transition node, and if not, return the error message of the program result;

所述第二判断模块,用于当所述第一判断模块判断的结果为是,将所述初始标志移入所述变迁节点的后库节点,判断所述程序执行序列是否还存在其他的节点,如果是,设置所述指针指向下一个节点,如果否,返回程序结果正确的信息。The second judging module is configured to move the initial flag into the back library node of the transition node when the judging result of the first judging module is yes, and judge whether there are other nodes in the program execution sequence, If yes, set the pointer to point to the next node, if no, return information that the program result is correct.

通过从源程序的文本文件中,获取指令信息,根据指令信息,建立串行队列,根据串行队列构造并行时序图,根据并行时序图,并行执行源程序,使得在一个扫描周期内能够执行整个源程序,不需要将源程序分成多段单独执行,或将源程序编写在不同的PLC上由各PLC单独执行,提高了开发源程序的效率,方便了调试和部署源程序。By obtaining instruction information from the text file of the source program, a serial queue is established according to the instruction information, a parallel sequence diagram is constructed according to the serial queue, and the source program is executed in parallel according to the parallel sequence diagram, so that the entire program can be executed in one scan cycle. For the source program, it is not necessary to divide the source program into multiple segments and execute it separately, or write the source program on different PLCs and each PLC executes it independently, which improves the efficiency of developing the source program and facilitates debugging and deployment of the source program.

附图说明Description of drawings

图1是本发明实施例1提供的一种执行程序的方法流程图;FIG. 1 is a flowchart of a method for executing a program provided in Embodiment 1 of the present invention;

图2是本发明实施例2提供的一种执行程序的方法流程图;FIG. 2 is a flow chart of a method for executing a program provided by Embodiment 2 of the present invention;

图3是本发明实施例提供的串行队列示意图;Fig. 3 is a schematic diagram of a serial queue provided by an embodiment of the present invention;

图4是本发明实施例提供的第一种并行时序图示意图;FIG. 4 is a schematic diagram of a first parallel timing diagram provided by an embodiment of the present invention;

图5是本发明实施例提供的第二种并行时序图示意图;FIG. 5 is a schematic diagram of a second parallel timing diagram provided by an embodiment of the present invention;

图6是本发明实施例提供的第三种并行时序图示意图;FIG. 6 is a schematic diagram of a third parallel timing diagram provided by an embodiment of the present invention;

图7是本发明实施例提供的连通分量示意图;Fig. 7 is a schematic diagram of connected components provided by an embodiment of the present invention;

图8是本发明实施例提供的新的并行时序图示意图;FIG. 8 is a schematic diagram of a new parallel sequence diagram provided by an embodiment of the present invention;

图9是本发明实施例3提供的一种验证程序结果的方法流程图;FIG. 9 is a flow chart of a method for verifying program results provided by Embodiment 3 of the present invention;

图10是本发明实施例提供的第四种并行时序图示意图;FIG. 10 is a schematic diagram of a fourth parallel timing diagram provided by an embodiment of the present invention;

图11是本发明实施例提供的Petri网模型示意图;Fig. 11 is a schematic diagram of a Petri net model provided by an embodiment of the present invention;

图12是本发明实施例提供的简化的Petri网模型示意图;Fig. 12 is a schematic diagram of a simplified Petri net model provided by an embodiment of the present invention;

图13是本发明实施例4提供的一种执行程序的装置示意图;Fig. 13 is a schematic diagram of a device for executing a program provided by Embodiment 4 of the present invention;

图14是本发明实施例5提供的一种验证程序结果的装置示意图;FIG. 14 is a schematic diagram of a device for verifying program results provided by Embodiment 5 of the present invention;

图15是本发明实施例6提供的一种执行程序的系统示意图。Fig. 15 is a schematic diagram of a system for executing a program provided by Embodiment 6 of the present invention.

具体实施方式Detailed ways

为使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明实施方式作进一步地详细描述。In order to make the object, technical solution and advantages of the present invention clearer, the implementation manner of the present invention will be further described in detail below in conjunction with the accompanying drawings.

实施例1Example 1

如图1所示,本发明实施例提供了一种执行程序的方法,包括:As shown in Figure 1, an embodiment of the present invention provides a method for executing a program, including:

101:从源程序的文本文件中,获取指令信息;101: Obtain instruction information from the text file of the source program;

其中,从源程序的文本文件中,获取指令信息的详细过程参见实施例2的201,在此不再赘述。Wherein, for the detailed process of obtaining instruction information from the text file of the source program, refer to 201 of Embodiment 2, which will not be repeated here.

102:根据指令信息,建立串行队列;102: Establish a serial queue according to the instruction information;

其中,根据指令信息,建立串行队列的详细过程参见实施例2的202,在此不再赘述。Wherein, for the detailed process of establishing the serial queue according to the instruction information, refer to 202 of Embodiment 2, which will not be repeated here.

103:根据串行队列,构造并行时序图;103: Construct a parallel sequence diagram according to the serial queue;

其中,根据串行队列,构造并行时序图的详细过程参见实施例2的203,在此不再赘述。Wherein, for the detailed process of constructing the parallel sequence diagram according to the serial queue, refer to 203 of Embodiment 2, which will not be repeated here.

104:根据并行时序图,并行执行源程序;104: Execute the source program in parallel according to the parallel sequence diagram;

其中,根据并行时序图,并行执行源程序的详细过程参见实施例2的205,在此不再赘述。Wherein, according to the parallel sequence diagram, refer to 205 of Embodiment 2 for the detailed process of executing the source program in parallel, which will not be repeated here.

其中,在本实施例中根据并行时序图,并行执行源程序,使得在一个扫描周期内能够执行整个源程序。Wherein, in this embodiment, according to the parallel sequence diagram, the source program is executed in parallel, so that the entire source program can be executed within one scan cycle.

在本发明实施例中,通过从源程序的文本文件,获取指令信息,根据指令信息,建立串行队列,根据串行队列构造并行时序图,根据并行时序图,并行执行源程序,使得在一个扫描周期内能够执行整个源程序,不需要将源程序分成多段单独执行,或将源程序编写在不同的PLC上由各PLC单独执行,提高了开发源程序的效率,方便了调试和部署源程序。In the embodiment of the present invention, by obtaining instruction information from the text file of the source program, a serial queue is established according to the instruction information, a parallel sequence diagram is constructed according to the serial queue, and the source program is executed in parallel according to the parallel sequence diagram, so that in a The entire source program can be executed within the scan cycle, without the need to divide the source program into multiple segments for separate execution, or write the source program on different PLCs and execute each PLC independently, which improves the efficiency of source program development and facilitates debugging and deployment of source programs .

实施例2Example 2

如图2所示,本发明实施例提供了一种执行程序的方法,包括:As shown in Figure 2, an embodiment of the present invention provides a method for executing a program, including:

201:扫描源程序的文本文件,获取指令信息;201: Scan the text file of the source program to obtain instruction information;

其中,源程序由一个或多个程序块组成,程序块由一个或多个Network(定界符)组成,Network由一条或多条指令组成。Wherein, the source program is composed of one or more program blocks, the program block is composed of one or more Networks (delimiters), and the Network is composed of one or more instructions.

具体地,顺序扫描源程序的文本文件的每行指令,读取指令所属的程序块、所属的Network、指令在所属的Network中的行号、指令名称和指令的操作数;获取操作数的存储空间,分析操作数的读写属性;估计指令的执行时间,将Network包括的指令的执行时间进行取和,得到Network的执行时间,将所属的程序块、所属的Network、指令的行号、指令名称、指令的操作数、执行时间、操作数的存储空间和操作数的读写属性作为指令信息,存储该指令信息。Specifically, sequentially scan each line of instructions in the text file of the source program, read the program block to which the instruction belongs, the Network to which the instruction belongs, the line number of the instruction in the Network to which the instruction belongs, the name of the instruction, and the operand of the instruction; obtain the storage of the operand Space, analyze the read and write properties of the operand; estimate the execution time of the instruction, sum the execution time of the instructions included in the Network, and obtain the execution time of the Network, the program block, the Network to which it belongs, the line number of the instruction, and the instruction The name, the operand of the instruction, the execution time, the storage space of the operand and the read/write attribute of the operand are used as the instruction information, and the instruction information is stored.

其中,在本实施例中获取操作数的存储空间的方法具体为:读取操作数的存储类型,根据操作数的存储类型从存储类型与起始基址之间的映射关系中查找该存储类型所占用的存储区的起始基址,根据操作数名称计算该操作数在该存储区中的上界偏移量和下界偏移量,将查找的起始基址分别与计算的上界偏移量和下界偏移量取和得到该操作数所在存储空间的上界地址和下界地址。Wherein, the method for obtaining the storage space of the operand in this embodiment is specifically: reading the storage type of the operand, and searching for the storage type from the mapping relationship between the storage type and the starting base address according to the storage type of the operand The starting base address of the occupied storage area, calculate the upper bound offset and lower bound offset of the operand in the storage area according to the name of the operand, and calculate the starting base address and the calculated upper bound offset The sum of the shift amount and the lower bound offset is obtained to obtain the upper bound address and lower bound address of the storage space where the operand is located.

其中,在本实施例中人为地为存储类型所占用的存储区分配一个起始基址,起始基址分配的原则是确保每个存储类型所占用的存储区之间不可能重叠。如表1所示为存储类型与起始基址之间的映射关系。Wherein, in this embodiment, a starting base address is artificially assigned to the storage area occupied by the storage type, and the principle of allocation of the starting base address is to ensure that the storage areas occupied by each storage type cannot overlap. Table 1 shows the mapping relationship between the storage type and the starting base address.

接下来以具体实例说明如何获取操作数的存储空间,例如,对于操作数SM2,读取该操作数的存储类型为SM,根据存储类型SM从表1中查找SM所在存储区的起始基址为2000,其中,需要说明的是:操作数SM2中的2含义是该操作数占用SM所在存储区的第三个字节,根据上述说明计算该操作数在SM所在存储区的上界偏移量为15和下界偏移量为23,将查找的起始基址2000分别与计算的上界偏移量15和下界偏移量23取和得到该操作数所在存储空间的上界地址为2015和下界地址为2023。另外,需要说明的是:操作数SM2.2中的2.2的含义是该操作数占用SM所在存储区的第三个字节的第三位,所以其上界偏移量和下界偏移量都为18,将起始基址分别与上界偏移量和下界偏移量取和,得到SM2.2所在存储空间的上界地址和下界地址都为2018。Next, use specific examples to illustrate how to obtain the storage space of the operand. For example, for the operand SM2, read the storage type of the operand as SM, and look up the starting base address of the storage area where the SM is located from Table 1 according to the storage type SM. It is 2000, where it needs to be explained that: the 2 in the operand SM2 means that the operand occupies the third byte of the storage area where the SM is located, and the upper bound offset of the operand in the storage area where the SM is located is calculated according to the above description The amount is 15 and the lower bound offset is 23, and the starting base address 2000 of the search and the calculated upper bound offset 15 and lower bound offset 23 are respectively summed to obtain the upper bound address of the storage space where the operand is located is 2015 And the lower bound address is 2023. In addition, it should be noted that: the meaning of 2.2 in the operand SM2.2 is that the operand occupies the third bit of the third byte of the storage area where the SM is located, so its upper bound offset and lower bound offset are both is 18, the starting base address is summed with the upper bound offset and the lower bound offset respectively, and the upper bound address and the lower bound address of the storage space where SM2.2 is located are both 2018.

另外,需要说明的是:由于CALL指令携带调用的程序块,在获取CALL指令的指令信息时,将调用的程序块也作为CALL指令的操作数,但该操作数不存在占用的存储空间以及读写属性,例如,CALL SBR1(程序块),将程序块名称SBR1作为该CALL指令的操作数。In addition, it should be noted that since the CALL instruction carries the called program block, when obtaining the instruction information of the CALL instruction, the called program block is also used as the operand of the CALL instruction, but the operand does not have the occupied storage space and read Write attributes, for example, CALL SBR1 (program block), use the program block name SBR1 as the operand of the CALL instruction.

表1Table 1

  存储类型storage type   起始基址Starting base address   II   00   QQ   200200   AIAI   400400   .........   .........   SMSM   20002000   .........   .........

接下来以一个具体的实施进行说明,如下所示的源程序,扫描该源程序获取指令信息:Next, a specific implementation will be used to describe the source program shown below. Scan the source program to obtain instruction information:

Figure GSB00000525756000091
Figure GSB00000525756000091

顺序扫描该段源程序,首先扫描的指令是该段源程序的声名部分,直到扫描到第五行指令LD SM0.0时,读取该条指令所属的程度块OB1、所属的Network即Network 1、指令在Network 1中的行号1、指令的操作数SM0.0;估计该指令的执行时间为0.8us;获取操作数SM0.0所在存储空间的上界地址为2000和下界地址为2000;需要说明的是:该条指令需要将操作数SM0.0先从对应的存储空间中读取出来,再对其操作,所以根据上述说明,分析出操作数SM0.0的读写属性为读;将程序块OB1、Network 1,该指令在Network 1的行号1、操作数SM0.0、执行时间0.8us、操作数SM0.0所在存储空间上界地址2000和下界地址2000,操作数SM0.0的读写属性作为该条指令的信息,将该条指令的信息存入表2;按上述方法扫描整个源程序,获取每条指令的指令信息,并存储在表2中,然后在表2,将每个Network包括的指令的执行时间取和,得到每个Network的执行时间,将Network的执行时间归入指令信息。Scan this section of source program sequentially, the first scanned instruction is the name part of this section of source program, until the fifth line of instruction LD SM0.0 is scanned, read the program block OB1 to which this instruction belongs, the Network to which it belongs, namely Network 1, The line number 1 of the instruction in Network 1, the operand SM0.0 of the instruction; the estimated execution time of the instruction is 0.8us; the upper bound address of the storage space where the operand SM0.0 is located is 2000 and the lower bound address is 2000; It is explained that this instruction needs to read the operand SM0.0 from the corresponding storage space first, and then operate on it, so according to the above description, it is analyzed that the read and write attribute of the operand SM0.0 is read; Program block OB1, Network 1, the instruction is in the line number 1 of Network 1, the operand SM0.0, the execution time is 0.8us, the upper bound address of the storage space where the operand SM0.0 is located is 2000 and the lower bound address is 2000, and the operand SM0.0 The read and write attribute of the instruction is used as the information of the instruction, and the information of the instruction is stored in Table 2; the entire source program is scanned according to the above method, and the instruction information of each instruction is obtained, and stored in Table 2, and then in Table 2, The execution time of the instructions included in each Network is summed to obtain the execution time of each Network, and the execution time of the Network is included in the instruction information.

表2Table 2

Figure GSB00000525756000101
Figure GSB00000525756000101

202:从指令信息的主程序块开始扫描指令信息,建立串行队列;202: Start scanning the instruction information from the main program block of the instruction information, and establish a serial queue;

其中,源程序包括的程序块中存在一个程序块为主程序块,即MAIN函数。Among the program blocks included in the source program, there is a program block as the main program block, that is, the MAIN function.

具体地,建立一个串行队列,在存储的指令信息中,以主程序块为入口,顺序扫描指令信息表中的Network包括的指令,将扫描的Network作为节点加入到串行队列,并判断扫描的指令是否为CALL指令,如果为CALL指令时,则跳入CALL指令调用的程序块,并从跳入的程序块的第一个Network开始扫描指令,重复上述扫描过程,直到扫描完存储的指令信息,得到整个源程序的串行队列。Specifically, a serial queue is established. In the stored instruction information, the main program block is used as the entry, and the instructions included in the Network in the instruction information table are sequentially scanned, and the scanned Network is added to the serial queue as a node, and the scan is judged. Whether the instruction is a CALL instruction, if it is a CALL instruction, jump into the program block called by the CALL instruction, and start scanning instructions from the first Network of the jump-in program block, repeat the above scanning process until the stored instructions are scanned Information, get the serial queue of the entire source program.

例如,在201中得到存储指令信息的表2,从主程序段OB1为入口,开始扫描表2,扫描到Network1时,将Network1作为节点加入到串行队列,扫描到Network2时,将Network2作为节点加入到串行队列,扫描到Network3时将Network3作为节点加入到串行队列,扫描到Network3中的第三行指令CALLOB2时,跳入到该CALL指令调用的程序块OB2,从程序块OB2的第一个Network开始扫描即扫描Network1,将扫描的Network1作为节点加入到串行队列中,得到上述源程序的串行队列如图3所示。For example, in 201, Table 2 for storing instruction information is obtained, start scanning Table 2 from the main program segment OB1, when Network1 is scanned, Network1 is added to the serial queue as a node, and Network2 is used as a node when Network2 is scanned Add to the serial queue. When Network3 is scanned, Network3 will be added to the serial queue as a node. When the third line of command CALLOB2 in Network3 is scanned, it will jump into the program block OB2 called by the CALL command, and start from the program block OB2. When a Network starts scanning, it scans Network1, and adds the scanned Network1 as a node to the serial queue, and the serial queue of the above source program is obtained as shown in Figure 3.

其中,在本实施例中将Network的执行时间作为节点的权重。Wherein, in this embodiment, the execution time of the Network is used as the weight of the node.

203:根据串行队列,构造并行时序图;203: Construct a parallel sequence diagram according to the serial queue;

具体地,将串行队列包括的所有节点存入并行时序图中,在串行队列中,设置指针1指向队头节点,设置指针2指向指针1指向的节点的下一个节点;根据操作数的存储空间和读写属性,判断指针1指向的节点与指针2指向的节点是否存在数据依赖关系,如果存在,在并行时序图中,在指针1指向的节点与指针2指向的节点之间加入有向边,方向为指针1指向的节点指向指针2指向的节点,同时,在串行队列中,重新设置指针2指向下一个节点;如果不存在,在串行队列中,重新设置指针2指向下一个节点;按上述方法扫描串行队列,直到指针2超过串行队列的队尾时,重新设置指针1指向下一个节点,指针2指向指针1指向的节点的下一个节点,重复执行上述扫描过程,按上述方法扫描串行队列,直到指针1超过串行队列的队尾时为止,就构造出并行时序图。Specifically, store all nodes included in the serial queue into the parallel sequence diagram, in the serial queue, set pointer 1 to point to the queue head node, set pointer 2 to point to the next node of the node pointed to by pointer 1; according to the operand Storage space and read/write attributes, determine whether there is a data dependency between the node pointed to by pointer 1 and the node pointed to by pointer 2, and if so, in the parallel sequence diagram, add a To the edge, the direction is that the node pointed to by pointer 1 points to the node pointed by pointer 2. At the same time, in the serial queue, reset pointer 2 to point to the next node; if it does not exist, reset pointer 2 to point to the next node in the serial queue One node; scan the serial queue according to the above method, until pointer 2 exceeds the end of the serial queue, reset pointer 1 to point to the next node, pointer 2 to the next node of the node pointed to by pointer 1, and repeat the above scanning process , scan the serial queue according to the above method, until the pointer 1 exceeds the tail of the serial queue, a parallel sequence diagram is constructed.

其中,数据依赖关系是指程序执行过程中,多条指令对相同存储空间进行读写操作,确定这些指令之间的序列关系。例如,对于源程序的两条指令即指令+I VW2,VW0和指令+I VW4,VW2,从表2中存储的指令信息中,查找出前一条指令的操作数VW2的存储空间为20016~20031以及读写属性为读,查找出后一条指令的操作数VW2的存储空间为20016~20031以及读写属性为先读后写,所以这两指令都对VW2对应的存储空间进行读取操作,所以这两条指令存在数据依赖关系。在本实施例中两个节点之间的任两条指令存在数据依赖关系,则可认为这两个节点存在数据依赖关系,例如,在源程序中指令+I VW2,VW0属于节点OB1-Network1,指令+I VW4,VW2属于节点OB1-Network2,所以这两个节点存在数据依赖关系。Among them, the data dependency means that during program execution, multiple instructions perform read and write operations on the same storage space, and determine the sequence relationship between these instructions. For example, for the two instructions of the source program, that is, instruction +I VW2, VW0 and instruction +I VW4, VW2, from the instruction information stored in Table 2, it is found that the storage space of the operand VW2 of the previous instruction is 20016-20031 and The read and write attribute is read, and the storage space of the operand VW2 of the next instruction is found to be 20016~20031, and the read and write attribute is read first and then write, so these two instructions both perform read operations on the storage space corresponding to VW2, so this There is a data dependency between the two instructions. In the present embodiment, any two instructions between the two nodes have a data dependency relationship, then it can be considered that the two nodes have a data dependency relationship, for example, in the source program, the instruction +I VW2, VW0 belongs to the node OB1-Network1, Instruction +I VW4, VW2 belongs to the node OB1-Network2, so there is a data dependency between these two nodes.

例如,扫描如图3所示的串行队列,将串行队列中的节点OB1-Network1、节点OB1-Network2、节点OB1-Network3和节点OB2-Network1存入并行时序图中,设置指针1指向节点OB1-Network1和指针2指向节点OB1-Network2,根据操作数的存储空间和读写属性,判断出节点OB1-Network1与节点OB1-Network2存在数据依赖关系,由于节点OB1-Network1中的指令LDSM0.0与节点OB1-Network2中的指令LD SM0.0都对操作数SM0.0的存储空间进行读写操作,因此这两条指令存在数据依赖关系,所以节点OB1-Network1与节点OB1-Network2存在数据依赖关系,在并行时序图中,在节点OB1-Network1与节点OB1-Network2之间添加有向边,方向由节点OB1-Network1指向节点OB1-Network2,同时,在串行队列中,重新设置指针2指向下一个节点即节点OB1-Network3,判断出节点OB1-Network1与节点OB1-Network3存在数据依赖关系,在并行时序图中,在节点OB1-Network1与节点OB1-Network3之间加入有向边,方向为由节点OB1-Network1指向节点OB1-Network3,重新设置指针2指向下一个节即节点OB2-Network1,判断出节点OB1-Network1与节点OB2-Network1之间不存在数据依赖关系,重新设置指针2指向下一个节点,此时指针2超过队尾,重新设置指针1指向下一个节点即节点OB1-Network2,指针2指向指针1指向的节点的下一个节点即OB1-Network3,重复执行上述扫描过程,按上述方法直到指针1超过队尾时为止,此时构造出源程序的整个并行时序图如图4所示。For example, scan the serial queue shown in Figure 3, store the nodes OB1-Network1, node OB1-Network2, node OB1-Network3, and node OB2-Network1 in the serial queue into the parallel sequence diagram, and set pointer 1 to point to the node OB1-Network1 and pointer 2 point to the node OB1-Network2. According to the storage space and read-write attributes of the operand, it is judged that there is a data dependency between the node OB1-Network1 and the node OB1-Network2. Because the instruction LDSM0.0 in the node OB1-Network1 The instruction LD SM0.0 in the node OB1-Network2 both reads and writes the storage space of the operand SM0.0, so there is a data dependency between the two instructions, so there is a data dependency between the node OB1-Network1 and the node OB1-Network2 Relationship, in the parallel sequence diagram, add a directed edge between the node OB1-Network1 and the node OB1-Network2, the direction is from the node OB1-Network1 to the node OB1-Network2, and at the same time, in the serial queue, reset the pointer 2 to point to The next node is the node OB1-Network3. It is judged that there is a data dependency between the node OB1-Network1 and the node OB1-Network3. In the parallel sequence diagram, a directed edge is added between the node OB1-Network1 and the node OB1-Network3, and the direction is From the node OB1-Network1 to the node OB1-Network3, reset the pointer 2 to point to the next node OB2-Network1, judge that there is no data dependency between the node OB1-Network1 and the node OB2-Network1, reset the pointer 2 to point down One node, at this time pointer 2 exceeds the end of the queue, reset pointer 1 to point to the next node, which is node OB1-Network2, and pointer 2 to point to the next node of the node pointed to by pointer 1, which is OB1-Network3, repeat the above scanning process, according to the above Method until the pointer 1 exceeds the end of the queue, at this time the entire parallel sequence diagram of the source program is constructed as shown in Figure 4.

204:可选地,从并行时序图中去除冗余边;204: Optionally, remove redundant edges from the parallel sequence graph;

其中,如图4所示,节点OB1-Network1先于节点OB1-Network2,节点OB1-Network2先于节点OB1-Network3,故蕴含着节点OB1-Network1先于节点OB1-Network3,所以图中的节点OB1-Network1与节点OB1-Network3之间的有向边为冗余边。Among them, as shown in Figure 4, the node OB1-Network1 precedes the node OB1-Network2, and the node OB1-Network2 precedes the node OB1-Network3, so it implies that the node OB1-Network1 precedes the node OB1-Network3, so the node OB1 in the figure The directed edge between -Network1 and node OB1-Network3 is a redundant edge.

具体地,通过拓扑排序算法对并行时序图中的节点进行遍历,将已经遍历过的节点加入队列中,读取正在遍历的节点的后继节点,从队列中查找是否存在该后继节点的前趋节点,如果存在,则标注该前趋节点与该后继节点之间的有向边为冗余边,同时将正在遍历的节点加入队列,通过拓扑排序算法遍历下一个节点;如果不存在,则将正在遍历的节点加入队列,通过拓扑排序算法遍历下一个节点,按上述方法标注并行时序图中的所有冗余边,从并行时序图中去除标注的冗余边。Specifically, the nodes in the parallel sequence diagram are traversed through the topological sorting algorithm, the traversed nodes are added to the queue, the successor nodes of the traversed nodes are read, and the predecessor nodes of the successor nodes are searched from the queue , if it exists, mark the directed edge between the predecessor node and the successor node as a redundant edge, and add the node being traversed to the queue, and traverse the next node through the topological sorting algorithm; if it does not exist, it will be The traversed nodes are added to the queue, and the next node is traversed through the topological sorting algorithm, and all redundant edges in the parallel sequence graph are marked according to the above method, and the marked redundant edges are removed from the parallel sequence graph.

例如,通过拓扑排序算法对如图4所示的并行时序图进行遍历,首先遍历节点OB1-Network1,读取节点OB1-Network1后继节点即节点OB1-Network2和节点OB1-Network3,由于此时队列为空,所以在队列中都不存在节点OB1-Network2和节点OB1-Network3的前趋节点,将节点OB1-Network1加入队列,通过拓扑排序算法遍历的下一个节点为节点OB1-Network2,读取节点OB1-Network2的后继节点为节点OB1-Network3,其中,节点OB1-Network3的前趋节点有节点OB1-Network1和节点OB1-Network2,从队列中查找出存在节点OB1-Network1,标注节点OB1-Network1与节点OB1-Network3之间的有向边为冗余边,按上述方法标注并行时序图中的所有冗余边,从并行时序图中去除冗余边,得到如图5所示的并行时序图。For example, to traverse the parallel sequence diagram shown in Figure 4 through the topology sorting algorithm, first traverse the node OB1-Network1, and read the successor nodes of node OB1-Network1, that is, node OB1-Network2 and node OB1-Network3, because the queue at this time is Empty, so there is no predecessor node of node OB1-Network2 and node OB1-Network3 in the queue, the node OB1-Network1 is added to the queue, the next node traversed by the topology sorting algorithm is the node OB1-Network2, and the node OB1 is read -The successor node of Network2 is the node OB1-Network3, among which, the predecessor nodes of the node OB1-Network3 include the node OB1-Network1 and the node OB1-Network2, find out the existence of the node OB1-Network1 from the queue, and mark the node OB1-Network1 and the node The directed edges between OB1-Network3 are redundant edges. Mark all the redundant edges in the parallel sequence diagram according to the above method, remove the redundant edges from the parallel sequence diagram, and obtain the parallel sequence diagram shown in Figure 5.

其中,将并行时序图中的冗余边去除可以提高调度并行时序图,执行源程序的效率。Wherein, removing redundant edges in the parallel sequence graph can improve the efficiency of scheduling the parallel sequence graph and executing the source program.

205:对204得到的并行时序图进行调度,并行执行源程序。205: Schedule the parallel sequence diagram obtained in 204, and execute the source program in parallel.

具体地,可以采用以下任意一种方法对并行时序图进行调度,并行执行源程序,包括:Specifically, any of the following methods can be used to schedule the parallel sequence diagram and execute the source program in parallel, including:

第一种方法,首先设置共享任务队列、一个主CPU和多个从CPU,其中,主CPU负责维护共享队列和分配任务给从CPU。该方法具体为:主CPU将并行时序图分解成多个连通分量,将每个连通分量作为一个任务存储在共享队列中,主CPU为每个从CPU分配一个任务,由从CPU执行任务中的节点,如果存在从CPU执行完分配的任务时,主CPU为其再分配任务,如果共享队列中的每个任务都被分配给从CPU并且从CPU都执行完了所有的任务时,整个源程序也就被执行完。In the first method, a shared task queue, a master CPU and multiple slave CPUs are first set up, wherein the master CPU is responsible for maintaining the shared queue and assigning tasks to the slave CPUs. The method is specifically as follows: the master CPU decomposes the parallel sequence diagram into multiple connected components, stores each connected component as a task in the shared queue, the master CPU assigns a task to each slave CPU, and the slave CPU executes the tasks in the task. Node, if there is a slave CPU that executes the assigned tasks, the master CPU reassigns tasks for it, if each task in the shared queue is assigned to the slave CPU and all tasks are executed from the CPU, the entire source program is also is executed.

其中,在本实施例中主CPU可以通过广度优先算法,将并行时序图分解成多个连通分量。Wherein, in this embodiment, the main CPU may decompose the parallel sequence graph into multiple connected components through a breadth-first algorithm.

例如,首先设置共享队列,一个主CPU和两个从CPU,然后主CPU通过广度优先算法,将如图6所示的并行时序图解成多个连通分量,即如图7所示的连通分量1、连通分量2和连通分量3,将连通分量1、连通分量2和连通分量3分别作为任务1、任务2和任务3,并将任务1、任务2和任务3存入共享队列,主CPU首先将任务1和任务2分配给两个从CPU,当某个从CPU执行完分配的任务时,主CPU再将任务3分配给该从CPU,当两个从CPU将任务执行完时,整个源程序就被执行完。For example, first set up a shared queue, one master CPU and two slave CPUs, and then the master CPU uses the breadth-first algorithm to graph the parallel timing sequence shown in Figure 6 into multiple connected components, that is, the connected component 1 shown in Figure 7 , Connected component 2 and Connected component 3, take Connected component 1, Connected component 2 and Connected component 3 as task 1, Task 2 and Task 3 respectively, and store Task 1, Task 2 and Task 3 in the shared queue, the main CPU first Assign task 1 and task 2 to two slave CPUs. When a slave CPU completes the assigned task, the master CPU assigns task 3 to the slave CPU. When the two slave CPUs complete the task, the entire source The program is executed.

第二种方法,首先设置共享任务队列、主CPU、多个从CPU以及为每个从CPU设置一个任务列表,其中,主CPU负责维护共享队列和分配任务给从CPU,从CPU将每次执行的结果返回给主CPU。该方法具体分为以下几个步骤:In the second method, first set up a shared task queue, master CPU, multiple slave CPUs, and set a task list for each slave CPU, where the master CPU is responsible for maintaining the shared queue and assigning tasks to the slave CPUs, and the slave CPUs will execute each The result is returned to the main CPU. The method is specifically divided into the following steps:

1:主CPU将并行时序图分解成多个连通分量;1: The main CPU decomposes the parallel sequence graph into multiple connected components;

例如,设置一个主CPU和两个从CPU,主CPU首先将如图6所示的并行时序图分解成三个连通分量,即如图7所示的连通分量1、连通分量2和连通分量3。For example, if one master CPU and two slave CPUs are set, the master CPU first decomposes the parallel timing diagram shown in Figure 6 into three connected components, namely connected component 1, connected component 2 and connected component 3 as shown in Figure 7 .

2:主CPU将针对一个连通分量,根据节点的权重从该连通分量中查找出关键路径(权重最大的一条路径),遍历该关键路径的节点,直到遍历出前趋节点为多个或后继节点为多个的节点时为止;为了便于说明将该节点称为第一停止节点。2: For a connected component, the main CPU will find out the critical path (a path with the largest weight) from the connected component according to the weight of the node, and traverse the nodes of the critical path until there are multiple predecessor nodes or the successor node is multiple nodes; for convenience of description, this node is referred to as the first stop node.

例如,如图7所示的三个连通分量,假设图中的每个节点的权重都为1,主CPU针对一个连通分量,假设连通分量2,从连通分量2中查找出关键路径为节点3、节点4、节点5、节点6、节点7和节点10,遍历该关键路径中的节点,直到遍历出后继节点为两个的节点3,将节点3称为第一停止节点。For example, for the three connected components shown in Figure 7, it is assumed that the weight of each node in the figure is 1, and the main CPU targets a connected component, assuming connected component 2, and finds out that the critical path from connected component 2 is node 3 , node 4, node 5, node 6, node 7 and node 10, and traverse the nodes in the critical path until a node 3 with two successor nodes is traversed, and node 3 is called the first stop node.

3:如果第一停止节点为前趋节点为多个的节点,主CPU将遍历过的节点中除第一停止节点之外的其他节点,从该连通分量中划分出来,将划分出的节点作为任务放入一个从CPU的任务列表,由该从CPU执行;如果第一停止节点为后继节点为多个的节点,主CPU将遍历过的节点,从该连通分量中划分出来,将划分出的节点作为任务放入到一个从CPU的任务列表,由该从CPU执行;3: If the first stop node is a node with multiple predecessor nodes, the main CPU will divide the other nodes from the traversed nodes except the first stop node from the connected component, and use the divided nodes as The task is put into a task list of a slave CPU, which is executed by the slave CPU; if the first stop node is a node with multiple successor nodes, the master CPU will divide the traversed nodes from the connected component, and divide the divided The node is put into the task list of a slave CPU as a task, and is executed by the slave CPU;

其中,当分解的连通分量的个数多于从CPU的个数时,主CPU重复地按照2至3两步为剩下的每个从CPU分配任务,当分解的连通分量的个数小于或等于从CPU的个数时,主CPU重复地按照2至3两步从剩下的每个连通分量中划分任务。Among them, when the number of decomposed connected components is more than the number of slave CPUs, the main CPU repeatedly assigns tasks to each of the remaining slave CPUs according to two steps 2 to 3, when the number of decomposed connected components is less than or When it is equal to the number of slave CPUs, the master CPU divides tasks from each of the remaining connected components repeatedly according to two steps of 2 to 3.

例如,第一停止节点即节点3是后继节点为两个的节点,将遍历的节点3从连通分量2中划分出来,将划分的节点3作为任务放入到一个从CPU的任务列表,由该从CPU执行,按照2和3两步从连通分量1中划分任务,将划分的任务分配给另一个从CPU。For example, the first stop node, i.e. node 3, is a node with two successor nodes, the traversed node 3 is divided from the connected component 2, and the divided node 3 is put into a task list from the CPU as a task. Execute from the CPU, divide tasks from connected component 1 according to steps 2 and 3, and assign the divided tasks to another slave CPU.

5:主CPU将所有的连通分量组成一个新的并行时序图;5: The main CPU forms all connected components into a new parallel sequence diagram;

具体地,如果分解的连通分量的个数多于从CPU的个数时,主CPU将被划分节点的连通分量和未被划分节点的连通分量组成新的并行时序图,如果分解的连通分量的个数小于或等于从CPU的个数时,主CPU将被划分节点的连通分量组成新的并行时序图;Specifically, if the number of decomposed connected components is more than the number of slave CPUs, the master CPU will form a new parallel sequence graph from the connected components of the divided nodes and the connected components of the undivided nodes, if the decomposed connected components When the number is less than or equal to the number of slave CPUs, the master CPU will be divided into connected components of nodes to form a new parallel sequence diagram;

例如,主CPU将被划分任务的连通分量2以及未被划分的连通分量3组成如图8所示的新的并行时序图。For example, the main CPU forms the connected component 2 of the divided task and the connected component 3 not divided into a new parallel sequence diagram as shown in FIG. 8 .

6:主CPU根据节点的权重从新的并行时序图中查找出关键路径,遍历该条关键路径,直到遍历出前趋节点为多个或后继节点为多个的节点时为止,为了便于说明将该节点称为第二停止节点;6: The main CPU finds the critical path from the new parallel sequence diagram according to the weight of the node, and traverses the critical path until a node with multiple predecessor nodes or multiple successor nodes is traversed. For the convenience of explanation, the node called the second stop node;

例如,主CPU从如图8所示的新的并行时序图中查找出关键路径为节点4、节点5、节点6、节点7和节点10,遍历该条关键路径直到找到前趋节点为2个的节点10,将节点10称为第二停止节点。For example, the main CPU finds out that the critical path is node 4, node 5, node 6, node 7 and node 10 from the new parallel sequence diagram shown in Figure 8, and traverses the critical path until it finds two predecessor nodes. node 10, and node 10 is called the second stop node.

7:如果第二停止节点为前趋节点为多个的节点,则主CPU将遍历过的节点中除第二停止节点之外的其他节点,从新的并行时序图中划分出来,将划分出的节点作为任务,并将该任务分配给能使开销达到最小的从CPU执行;如果第二停止节点为后继节点为多个的节点,则主CPU将遍历过的节点从新的并行时序图中划分出来,将划分出的节点作为任务,并将该任务分配给能使开销达到最小的从CPU执行。7: If the second stop node is a node with multiple predecessor nodes, the main CPU will divide other nodes from the traversed nodes except the second stop node from the new parallel sequence diagram, and divide the divided The node is used as a task, and the task is assigned to the slave CPU that can minimize the overhead; if the second stop node is a node with multiple successor nodes, the master CPU divides the traversed nodes from the new parallel sequence diagram , take the divided nodes as tasks, and assign the task to the slave CPU that can minimize the overhead.

其中,主CPU重复的按照6和7两步,将新的并行时序图中的所有节点都划分完,并从CPU执行完所有的任务时,整个源程序也被执行完。Wherein, the main CPU divides all nodes in the new parallel sequence diagram repeatedly according to steps 6 and 7, and when the slave CPU finishes executing all tasks, the entire source program is also executed.

例如,主CPU遍历由节点4、节点5、节点6、节点7和节点10组成的关键路径,直到查找到前趋节点为两个的节点10为止,将节点10称为第二停止节点,将遍历过的节点中除第二停止节点之外的节点,从新的并行时序图中划分出来,即划分出节点4、节点5、节点6和节点7,将划分出的节点作为任务,并将该任务分配给能使开销达到最小的从CPU执行。其中,当主CPU将新的并行时序图中的节点都被划分完,并且从CPU执行完所有的任务时,整个源程序都被执行完。For example, the main CPU traverses the critical path formed by node 4, node 5, node 6, node 7 and node 10, until finding node 10 with two predecessor nodes, node 10 is called the second stop node, and Among the traversed nodes, the nodes other than the second stop node are divided from the new parallel sequence diagram, that is, node 4, node 5, node 6 and node 7 are divided, and the divided nodes are used as tasks, and the Tasks are assigned to the slave CPUs that minimize overhead. Wherein, when the master CPU divides all the nodes in the new parallel sequence diagram and executes all the tasks of the slave CPU, the entire source program is executed.

其中,在步骤7中,主CPU划分任务后需要先找出能使开销达到最小的从CPU,具体为:主CPU读取任务的第一个节点的前趋节点,从每个从CPU列表中查找该前趋节点,如果某个从CPU列表中存在该前趋节点,则将当前任务最多的从CPU作为能使开销达到最小的从CPU,如果所有的从CPU的列表中都不存在该前趋节点,则将当前任务最少的从CPU作为能使开销达到最小的从CPU。Among them, in step 7, after the master CPU divides the tasks, it needs to first find out the slave CPU that can minimize the overhead, specifically: the master CPU reads the predecessor node of the first node of the task, from each slave CPU list Find the predecessor node, if the predecessor node exists in a slave CPU list, take the slave CPU with the most current tasks as the slave CPU that can minimize the overhead, if the predecessor node does not exist in all slave CPU lists If the node is trending, the slave CPU with the least current task is taken as the slave CPU that can minimize the overhead.

另外,需要说明的是,从CPU在执行任务的第一个节点时,若执行该节点需要该节点的前趋节点被执行的结果时,则该从CPU向主CPU请求该结果,当主CPU已有该结果,则返回该结果给该从CPU,若没有,则该前趋节点还未被其他的从CPU执行,此时,该从CPU还需要等待,直到该前趋节点被执行后,主CPU接收来自其他从CPU返回的该结果,才将该结果再返回给该从CPU。其中,在执行源程序的过程中,这种主CPU与从CPU之间的通信模式为主从模式。In addition, it should be noted that when the slave CPU executes the first node of the task, if the execution of the node requires the execution result of the predecessor node of the node, the slave CPU requests the result from the master CPU. If there is this result, then return the result to the slave CPU, if not, then the predecessor node has not been executed by other slave CPUs, at this time, the slave CPU still needs to wait until the predecessor node is executed, the master The CPU receives the result returned from other slave CPUs, and then returns the result to the slave CPU. Wherein, in the process of executing the source program, the communication mode between the master CPU and the slave CPU is master-slave mode.

另外,需要说明的是:从CPU在执行源程序的第一个节点时,若执行该节点需要该节点的前趋节点被执行的结果时,则该执行任务的从CPU也可以向执行该前趋节点的从CPU请求该结果,如果执行该前趋节点的从CPU有该结果,则将该结果返回,如果没有,则直到执行完该前趋节点,得到该结果后,再将该结果返回。其中,在执行源程序的过程中,这种从CPU与从CPU之间的通信模式称为对等模式。In addition, it should be noted that: when the slave CPU executes the first node of the source program, if the execution of the node requires the result of the execution of the predecessor node of the node, the slave CPU of the execution task can also execute the result of the predecessor node. The slave CPU of the trend node requests the result. If the slave CPU of the predecessor node has the result, the result will be returned. If not, the result will be returned after the predecessor node is executed and the result is obtained. . Wherein, in the process of executing the source program, this communication mode between the slave CPU and the slave CPU is called peer-to-peer mode.

以上予以说明的是在主从模式下调度算法的执行过程,本发明中所提出的调度方法同样适用于CPU完全对等模式,只需略加修改,取消专职通信的主CPU,而使通信双方的CPU两两相互通信即可。What has been explained above is the execution process of the scheduling algorithm under the master-slave mode. The scheduling method proposed in the present invention is also applicable to the CPU full peer-to-peer mode. The CPUs can communicate with each other in pairs.

其中,在本实施例中对并行时序图进行调度,并行执行源程序,使得在一个扫描周期内能够执行整个源程序,从而不需要将源程序分成多段单独执行,也不需要将源程序编写在多个PLC上。Wherein, in this embodiment, the parallel timing diagram is scheduled, and the source program is executed in parallel, so that the entire source program can be executed in one scan cycle, so that the source program does not need to be divided into multiple segments to be executed separately, and the source program does not need to be written in on multiple PLCs.

在本发明实施例中,通过扫描源程序的文本文件,获取指令信息,扫描指令信息,建立串行队列,根据串行队列构造并行时序图,对并行时序图进行调度,并行执行源程序,使得在一个扫描周期内能够执行整个源程序,不需要将源程序分成多段单独执行或将源程序编写在不同的PLC上,提高了开发源程序的效率,方便了调试和部署源程序。In the embodiment of the present invention, by scanning the text file of the source program, instruction information is acquired, the instruction information is scanned, a serial queue is established, a parallel timing diagram is constructed according to the serial queue, the parallel timing diagram is scheduled, and the source program is executed in parallel, so that The entire source program can be executed in one scan cycle, without the need to divide the source program into multiple segments for separate execution or write the source program on different PLCs, which improves the efficiency of source program development and facilitates debugging and deployment of source programs.

实施例3Example 3

本发明实施例提供了一种验证程序结果的方法,在实施例2中CPU记录源程序的每个节点被执行的时间,根据该时间对源程序包括的节点进行排序,得到节点被执行的序列即程序执行序列,本实施例通过对该程序执行序列进行验证,得出实施例2执行源程序的结果是否正确。如图9所示,该方法包括:The embodiment of the present invention provides a method for verifying program results. In Embodiment 2, the CPU records the execution time of each node of the source program, sorts the nodes included in the source program according to the time, and obtains the sequence in which the nodes are executed That is, the program execution sequence. This embodiment verifies the program execution sequence to determine whether the result of executing the source program in Embodiment 2 is correct. As shown in Figure 9, the method includes:

301:将并行时序图中的每个节点转换成Petri网模型中的变迁节点;301: Convert each node in the parallel sequence diagram into a transition node in the Petri net model;

其中,并行时序图为实施例2得到的并行时序图,Petri网模型由变迁(Transition)和库(Place)两类节点组成,且变迁节点前后直接相连的节点都是库节点,库节点前后直接相连的节点都是变迁节点,其中,变迁节点用于表示系统中的某个动作或涉及状态改变的事件,库节点用于表示事件发生所涉及的具体条件,包括前置条件和后置条件。其中,在本实施例中将Petri网模型中的变迁节点前后直接相连的库节点分别称为前库节点和后库节点,前库节点用于存放该变迁节点发生的前置条件,后库节点用于存放该变迁节点发生的后置条件。当变迁节点发生时,该变迁节点的前库节点存放的前置条件移入到该变迁节点的后库节点中,或该变迁节点的后库节点存放的后置条件移入到该变迁节点的前库节点中。Among them, the parallel sequence diagram is the parallel sequence diagram obtained in Example 2. The Petri net model is composed of two types of nodes, transition (Transition) and place (Place), and the nodes directly connected before and after the transition node are all library nodes. The connected nodes are all transition nodes. The transition node is used to represent an action in the system or an event involving state change, and the library node is used to represent the specific conditions involved in the occurrence of the event, including preconditions and postconditions. Among them, in this embodiment, the library nodes directly connected before and after the transition nodes in the Petri net model are respectively referred to as front library nodes and back library nodes. It is used to store the post-conditions of the occurrence of the transition node. When a transition node occurs, the preconditions stored in the front library node of the transition node are moved into the back library node of the transition node, or the postconditions stored in the back library node of the transition node are moved into the front library node of the transition node node.

其中,在本实施例中将并行时序图中的节点作为Petri网模型中的变迁节点,具体地,建立并行时序图中的节点与Petri网模型中变迁节点之间的一一映射关系,根据建立的映射关系将并行时序图的中节点转换成Petri网模型中的变迁节点。Wherein, in this embodiment, the nodes in the parallel sequence diagram are used as the transition nodes in the Petri net model, specifically, the one-to-one mapping relationship between the nodes in the parallel sequence diagram and the transition nodes in the Petri net model is established, according to the established The mapping relation of converts the nodes in the parallel sequence graph into transition nodes in the Petri net model.

302:根据并行时序图的拓扑结构,连接Petri网模型中的变迁节点;302: Connect transition nodes in the Petri net model according to the topology structure of the parallel sequence diagram;

具体地,在Petri网模型中,在变迁节点之前添加前库节点,在变迁节点之后添加后库节点,连接前库节点与变迁节点以及变迁节点与后库节点,以并行时序图的拓扑结构为参照对象,将Petri网模型中前后相邻的两库节点之间添加虚拟变迁节点,连接前库节点与虚拟变迁节点以及虚拟变迁节点与后库节点,从而连接了Petri网模型中的所有变迁节点。Specifically, in the Petri net model, the front-storage node is added before the transition node, the back-storage node is added after the transition node, and the front-storage node and the transition node are connected, as well as the transition node and the back-storage node. The topology structure of the parallel sequence diagram is Referring to the object, add a virtual transition node between the two adjacent storage nodes in the Petri net model, connect the front storage node and the virtual transition node, and the virtual transition node and the back storage node, thus connecting all the transition nodes in the Petri net model .

例如,将如图10所示的并行时序图中的节点转换成Petri网模型中的变迁节点,在变迁节点的前后分别添加前库节点和后库节点,分别连接前库节点和变迁节点以及变迁节点与后库节点,以如图10所示的并行时序图为参照对象,在连续相邻的两个库节点之间添加虚拟变迁节点,分别连接前库节点与虚拟变迁节点以及虚拟变迁节点与后库节点,得到如图11所示的Petri网模型。For example, convert the nodes in the parallel sequence diagram shown in Figure 10 into transition nodes in the Petri net model, add front-storage nodes and back-storage nodes before and after the transition nodes, and connect the front-storage nodes and transition nodes and transition nodes respectively. Nodes and post-base nodes, taking the parallel sequence diagram shown in Figure 10 as a reference object, add a virtual transition node between two consecutive adjacent library nodes, respectively connect the front-base node and the virtual transition node, and the virtual transition node and After the library node, the Petri net model shown in Figure 11 is obtained.

303:简化连接的Petri网模型;303: Petri net model of simplified connection;

具体地,在Petri网模型中,将虚拟变迁节点、该虚拟变迁节点的前库节点和该虚拟变迁节点的后库节点合并为一个库点表示。Specifically, in the Petri net model, the virtual transition node, the front bank node of the virtual transition node and the back bank node of the virtual transition node are combined into a pool point representation.

例如,在如图11所示的Petri网模型中,将虚拟的变迁节点、该虚拟变迁节点的前库节点和该虚拟变迁节点的后库节点合并为一个库节点,得到如图12所示的Petri网模型。For example, in the Petri net model shown in Figure 11, the virtual transition node, the front library node of the virtual transition node and the back library node of the virtual transition node are merged into one library node, and as shown in Figure 12, Petri net model.

304:在简化的Petri网模型的第一个库节点中设置初始标志;304: Set an initial flag in the first library node of the simplified Petri net model;

其中,在本实施例中将初始标志作为执行变迁节点的条件,当执行变迁节点时,其前库节点必须存放有该初始标志,否则,执行出错。Wherein, in this embodiment, the initial flag is used as the condition for executing the transition node. When the transition node is executed, the initial flag must be stored in the previous library node, otherwise, an execution error occurs.

305:在执行304之后,设置指针指向程序执行序列中的第一个节点;305: After executing 304, set the pointer to point to the first node in the program execution sequence;

306:将指针指向的节点映射到Petri网模型中对应的变迁节点;306: Map the node pointed by the pointer to the corresponding transition node in the Petri net model;

307:判断该变迁节点的前库节点中是否存在初始标志,如果存在,执行308,否则,操作结束,返回程序结果出错的信息;307: Judging whether there is an initial flag in the front library node of the transition node, if it exists, execute 308, otherwise, the operation ends, and the error message of the program result is returned;

例如,在如图11所示的Petri网模型的第一个库节点中设置初始状态X,对于程序执行序列即节点A、节点B、节点C和节点D,首先设置指针指向节点A,将节点A映射到该Petri网模型中的变迁节点A,判断出变迁节点A的前库节点是存在初始标志X,执行308。For example, set the initial state X in the first library node of the Petri net model shown in Figure 11, for the program execution sequence that is node A, node B, node C and node D, first set the pointer to point to node A, set the node A is mapped to transition node A in the Petri net model, and it is judged that the former storage node of transition node A has an initial mark X, and 308 is executed.

308:执行该变迁节点,即将该变迁节点的前库节点的初始标志移入后库节点中,当程序执行序列还存在其他的节点,则重新设置指针指向下一个节点,返执行306,否则,返回程序结果正确的信息。308: Execute the transition node, that is, move the initial mark of the front library node of the transition node into the back library node. When there are other nodes in the program execution sequence, reset the pointer to point to the next node, and return to 306, otherwise, return Program results correct information.

例如,将初始标志X移入到变迁节点A的后库节点中,重新设置指针指向节点B,返回306。For example, move the initial mark X into the back library node of transition node A, reset the pointer to point to node B, and return 306.

其中,在本实施例中如果返回的结果为程序结果出错的信息,则实施例2执行源程序的结果不正确,如果返的结果为程序结果正确的信息,则实施例2执行源程序的结果正确。Wherein, in this embodiment, if the returned result is information that the program result is wrong, the result of executing the source program in embodiment 2 is incorrect; if the returned result is information that the program result is correct, then the result of executing the source program in embodiment 2 correct.

在本发明实施例中,通过并行时序图构建出Petri网模型,根据Petri网模型,验证程序执行序列是否正确,从而得出源程序的执行结果是否正确。In the embodiment of the present invention, the Petri net model is constructed through the parallel sequence diagram, and according to the Petri net model, it is verified whether the program execution sequence is correct, so as to determine whether the execution result of the source program is correct.

实施例4Example 4

如图所示,本发明实施例提供了一种执行程序的装置,包括:As shown in the figure, an embodiment of the present invention provides an apparatus for executing a program, including:

获取模块401,用于从源程序的文本文件中,获取指令信息;An acquisition module 401, configured to acquire instruction information from the text file of the source program;

建立模块402,用于根据获取的指令信息,建立串行队列;A building module 402, configured to set up a serial queue according to the acquired instruction information;

构造模块403,用于根据建立的串行队列,构造并行时序图;A construction module 403, configured to construct a parallel sequence diagram according to the established serial queue;

执行模块404,用于根据构造的并行时序图,并行执行源程序。The execution module 404 is configured to execute the source program in parallel according to the constructed parallel sequence diagram.

其中,获取模块401具体包括:Wherein, the acquisition module 401 specifically includes:

第一扫描单元,用于顺序扫描源程序的文本文件中的指令;The first scanning unit is used to sequentially scan the instructions in the text file of the source program;

读取单元,用于读取指令的名称和操作数、指令所属的Network以及所属的程序块;The reading unit is used to read the name and operand of the instruction, the Network to which the instruction belongs, and the program block to which it belongs;

计算单元,用于计算Network的执行时间;Computing unit, used to calculate the execution time of the Network;

第一获取单元,用于获取操作数的存储空间和读写属性;The first acquisition unit is used to acquire the storage space and read/write attributes of the operand;

将指令的名称、指令的操作数、指令所属的Network以及所属的程序块、Network的执行时间、操作数的存储空间和读写属性作为指令信息;Use the name of the instruction, the operand of the instruction, the Network to which the instruction belongs and the program block to which it belongs, the execution time of the Network, the storage space of the operand, and the read and write attributes as the instruction information;

建立模块402具体包括:The building module 402 specifically includes:

建立单元,用于建立串行队列;Establishing a unit for establishing a serial queue;

第二扫描单元,用于从指令信息的程序块的主程序块为入口,顺序扫描指令信息中的Network包括的指令;The second scanning unit is used to be an entry from the main program block of the program block of the instruction information, and sequentially scans the instructions included in the Network in the instruction information;

添加单元,用于将扫描的Network作为节点添加到串行队列,其中,将Network的执行时间作为节点的权重;The addition unit is used to add the scanned Network as a node to the serial queue, wherein the execution time of the Network is used as the weight of the node;

判断单元,用于判断扫描的指令是否为CALL指令,如果扫描的指令为CALL指令时,跳入CALL指令调用的程序块,扫描调用的程序块中的Network包括的指令;Judging unit, for judging whether the scanned instruction is a CALL instruction, if the scanned instruction is a CALL instruction, jump into the program block called by the CALL instruction, and scan the instructions included in the Network in the called program block;

构造模块403具体包括:The construction module 403 specifically includes:

存储单元,用于将串行队列中的节点存入并行时序图中;The storage unit is used to store the nodes in the serial queue into the parallel timing diagram;

第一设置单元,用于在串行队列中,设置指针1指向队头节点,设置指针2指向指针1指向的节点的下一个节点;The first setting unit is used to set the pointer 1 to point to the queue head node in the serial queue, and set the pointer 2 to point to the next node of the node pointed to by the pointer 1;

第一判断单元,用于判断指针1指向的节点与指针2指向的节点是否存在数据依赖关系,如果存在,在并行时序图中,在指针1指向的节点与指针2指向的节点之间加入有向边,方向为指针1指向的节点指向指针2指向的节点,在串行队列中,重新设置指针2指向下一个节点;如果不存在,在串行队列中,重新设置指针2指向下一个节点;The first judging unit is used to judge whether there is a data dependency relationship between the node pointed to by pointer 1 and the node pointed to by pointer 2. To the edge, the direction is that the node pointed to by pointer 1 points to the node pointed by pointer 2. In the serial queue, reset pointer 2 to point to the next node; if it does not exist, reset pointer 2 to point to the next node in the serial queue ;

可选地,执行模块404具体包括:Optionally, the execution module 404 specifically includes:

第一分解单元,用于将并行时序图分解成连通分量;a first decomposition unit, configured to decompose the parallel sequence graph into connected components;

第一分配单元,用于将分解的连通分量分配给CPU,由该CPU执行分配的连通分量的节点;The first assignment unit is used to assign the decomposed connected components to the CPU, and the CPU executes the nodes of the assigned connected components;

可选地,执行模块404具体包括Optionally, the execution module 404 specifically includes

第二分解单元,用于将并行时序图分解成连通分量;The second decomposition unit is used to decompose the parallel sequence graph into connected components;

第一查找单元,用于根据节点的权重查找连通分量的关键路径;The first search unit is used to find the critical path of the connected component according to the weight of the node;

划分单元,用于根据查找的关键路径,从连通分量中划分节点,将划分的节点分配给CPU,由该CPU执行划分的节点;The division unit is used to divide the nodes from the connected components according to the key path searched, and assign the divided nodes to the CPU, and the CPU executes the divided nodes;

组成单元,用于将连通分量组成新的并行时序图;A composition unit for composing connected components into a new parallel sequence graph;

寻找单元,用于从新的并行时序图中,寻找关键路径;A search unit is used to find a critical path from the new parallel sequence diagram;

分离单元,用于根据寻找的关键路径,从新的并行时序图中分离节点,将分离的节点分配给CPU,由该CPU执行分离的节点;A separation unit is used to separate nodes from the new parallel sequence diagram according to the critical path to be found, assign the separated nodes to CPUs, and execute the separated nodes by the CPUs;

其中,划分单元具体包括:Among them, the division unit specifically includes:

第一遍历子单元,用于遍历查找的关键路径,直到遍历出前趋节点为多个或后继节点为多个的节点时为止,为了便于说明将该节点称为第一停止节点;The first traversal subunit is used for traversing the key path of the search until a node with multiple predecessor nodes or multiple successor nodes is traversed. For the convenience of description, this node is called the first stop node;

第一划分子单元,用于如果第一停止节点为前趋节点为多个的节点,将遍历的节点中除第一停止节点之外的节点,从连通分量中划分出来,将划分的节点分配给CPU;The first division subunit is used to divide the nodes traversed except the first stop node from the connected components if the first stop node is a node with multiple predecessor nodes, and assign the divided nodes to the CPU;

第二划分子单元,用于如果第一停止节点为后继节点为多个的节点,从连通分量划分遍历的节点,将划分的节点分配给CPU;The second division subunit is used to divide the traversed nodes from the connected components if the first stop node is a node with multiple successor nodes, and distribute the divided nodes to the CPU;

分离单元具体包括:The separation unit specifically includes:

第二遍历子单元,用于遍历找出的关键路径,直到遍历出前趋节点为多个或后继节点为多个的节点时为止,为了便于说明将该节点称为第二停止节点;The second traversal subunit is used to traverse the found critical path until a node with multiple predecessor nodes or multiple successor nodes is traversed. For the convenience of description, this node is called the second stop node;

第三划分子单元,用于如果第二停止节点为前趋节点为多个的节点,将遍历的节点中除第二停止节点之外的节点,从新的并行时序图中划分出来,将划分的节点分配给能使开销达到最小的CPU;The third dividing subunit is used to divide the nodes in the traversed nodes except the second stopping node from the new parallel sequence diagram if the second stop node is a node with multiple predecessor nodes, and divide the divided nodes Nodes are assigned to CPUs that minimize overhead;

第四划分子单元,用于如果第二停止节点为后继节点为多个的节点,从新的并行时序图中,划分遍历的节点,将划分的节点分配给能使开销达到最小的CPU;The fourth division subunit is used to divide the traversed nodes from the new parallel sequence diagram if the second stop node is a node with multiple successor nodes, and allocate the divided nodes to the CPU that can minimize the overhead;

进一步地,该执行程序的装置还包括:Further, the device for executing the program also includes:

遍历模块,用于通过拓扑排序算法对并行时序图中的节点进行遍历,将已遍历的节点加入队列中,读取正在遍历的节点的后继节点;The traversal module is used to traverse the nodes in the parallel sequence diagram through the topology sorting algorithm, add the traversed nodes to the queue, and read the successor nodes of the traversed nodes;

查找模块,用于从队列中查找是否存在后继节点的前趋节点,如果存在,则标注前趋节点与后继节点之间的有向边为冗余边,将正在遍历的节点加入队列,通过拓扑排序算法遍历下一个节点;如果不存在,则将正在遍历的节点加入队列,通过拓扑排序算法遍历下一个节点;The search module is used to find out whether there is a predecessor node of the successor node from the queue. If it exists, mark the directed edge between the predecessor node and the successor node as a redundant edge, add the node being traversed to the queue, and pass the topology The sorting algorithm traverses the next node; if it does not exist, the node being traversed is added to the queue, and the next node is traversed through the topological sorting algorithm;

去除模块,用于从并行时序图中去除冗余边。Removal module for removing redundant edges from parallel timing diagrams.

其中,在本实施例中根据并行时序图,并行执行源程序,使得在一个扫描周期内能够执行整个源程序。Wherein, in this embodiment, according to the parallel sequence diagram, the source program is executed in parallel, so that the entire source program can be executed within one scan cycle.

在本发明实施例中,通过从源程序的文本文件中,获取指令信息,扫描指令信息,建立串行队列,根据串行队列构造并行时序图,根据并行时序图,并行执行源程序,使得在一个扫描周期内执行整个源程序,不需要将源程序分成多段单独执行或将源程序编写在不同的PLC上,由各PLC单独执行,提高了开发源程序的效率,方便了调试和部署源程序。In the embodiment of the present invention, by obtaining instruction information from the text file of the source program, scanning the instruction information, establishing a serial queue, constructing a parallel timing diagram according to the serial queue, and executing the source program in parallel according to the parallel timing diagram, so that Execute the entire source program in one scan cycle, without dividing the source program into multiple segments for separate execution or writing the source program on different PLCs, each PLC executes it independently, which improves the efficiency of source program development and facilitates debugging and deployment of source programs .

实施例5Example 5

如图所示,本发明实施例提供了一种验证程序结果的装置,包括:As shown in the figure, an embodiment of the present invention provides a device for verifying program results, including:

创建模块501,用于根据并行时序图,创建Petri网模型;Creating module 501, for creating a Petri net model according to the parallel sequence diagram;

第一设置模块502,用于在创建的Petri网模型中的第一个库节点中设置初始标志;The first setting module 502 is used to set the initial sign in the first library node in the created Petri net model;

第二设置模块503,用于在第一设置模块502设置初始标志之后,设置指针指向程序执行序列中的第一个节点;The second setting module 503 is used to set the pointer to point to the first node in the program execution sequence after the initial flag is set by the first setting module 502;

映射模块504,用于将指针指向的节点映射到Petri网模型中对应的变迁节点;A mapping module 504, configured to map the node pointed to by the pointer to the corresponding transition node in the Petri net model;

第一判断模块505,用于判断映射的变迁节点的前库节点中是否存在初始标志,如果否,则返回程序结果出错的信息;The first judging module 505 is used to judge whether there is an initial mark in the front library node of the transition node of the mapping, if not, then return the information that the program result is wrong;

第二判断模块506,用于当第一判断模块505判断的结果为是时,将初始标志移入映射的变迁节点的后库节点,判断程序执行序列是否还存在其他的节点,如果是,设置指针指向下一个节点,如果否,返回程序结果正确的信息。The second judging module 506 is used for when the result of judging by the first judging module 505 is yes, move the initial flag into the back library node of the transition node of the mapping, judge whether there are other nodes in the program execution sequence, and if so, set the pointer Point to the next node, if not, return the information that the program result is correct.

其中,创建模块501具体包括:Wherein, the creation module 501 specifically includes:

转换单元,用于将并行时序图中的节点转换成Petri网模型中变迁节点;A conversion unit is used to convert the nodes in the parallel sequence graph into transition nodes in the Petri net model;

连接单元,用于根据并行时序图的拓扑结构,连接Petri网模型中的变迁节点;The connection unit is used to connect the transition nodes in the Petri net model according to the topology of the parallel sequence diagram;

简化单元,用于简化Petri网模型。Simplification unit, used to simplify the Petri net model.

在本发明实施例中,通过将并行时序图构建出Petri网模型,根据Petri网模型,验证程序执行序列是否正确,从而得出源程序的执行结果是否正确。In the embodiment of the present invention, a Petri net model is constructed by constructing a parallel sequence diagram, and according to the Petri net model, it is verified whether the program execution sequence is correct, so as to obtain whether the execution result of the source program is correct.

实施例6Example 6

如图15所示,本发明实施例提供了一种执行程序的系统,包括:As shown in Figure 15, an embodiment of the present invention provides a system for executing programs, including:

执行程序的装置601,用于从源程序的文本文件中,获取指令信息;根据获取的指令信息,建立串行队列;根据建立的串行队列,构造并行时序图;根据构造的并行时序图,并行执行源程序;The device 601 for executing the program is used to obtain instruction information from the text file of the source program; establish a serial queue according to the obtained instruction information; construct a parallel sequence diagram according to the established serial queue; and construct a parallel sequence diagram according to the constructed parallel sequence diagram, Execute the source program in parallel;

验证程序结果的装置602,用于根据构造的并行时序图,创建Petri网模型;在创建的Petri网模型中的第一个库节点中设置初始标志;设置指针指向程序执行序列中的第一个节点;将指针指向的节点映射到创建的Petri网模型中对应的变迁节点;判断映射的变迁节点的前库节点中是否存在初始标志,如果是,将初始标志移入映射的变迁节点的后库节点;如果否,则返回程序结果出错的信息;判断程序执行序列是否还存在其他的节点,如果是,设置指针指向下一个节点,如果否,返回程序结果正确的信息。The device 602 for verifying program results is used to create a Petri net model according to the constructed parallel sequence diagram; set the initial flag in the first library node in the created Petri net model; set the pointer to point to the first in the program execution sequence Node; map the node pointed to by the pointer to the corresponding transition node in the created Petri net model; judge whether there is an initial mark in the front library node of the mapped transition node, and if so, move the initial mark into the back library node of the mapped transition node ; If not, return the information that the program result is wrong; judge whether there are other nodes in the program execution sequence, if yes, set the pointer to point to the next node, if not, return the correct information of the program result.

其中,在本实施例中根据并行时序图,并行执行源程序,使得在一个扫描周期内执行整个源程序。Wherein, in this embodiment, according to the parallel sequence diagram, the source program is executed in parallel, so that the entire source program is executed within one scan cycle.

在本发明实施例中,通过从源程序的文本文件中,获取指令信息,根据指令信息,建立串行队列,根据串行队列构造并行时序图,根据并行时序图,并行执行源程序,使得在一个扫描周期内执行整个源程序,不需要将源程序分成多段单独执行或将源程序编写在不同的PLC上,由各PLC单独执行,提高了开发源程序的效率,方便了调试和部署源程序。In the embodiment of the present invention, by obtaining instruction information from the text file of the source program, a serial queue is established according to the instruction information, a parallel sequence diagram is constructed according to the serial queue, and the source program is executed in parallel according to the parallel sequence diagram, so that in Execute the entire source program in one scan cycle, without dividing the source program into multiple segments for separate execution or writing the source program on different PLCs, each PLC executes it independently, which improves the efficiency of source program development and facilitates debugging and deployment of source programs .

以上实施例提供的技术方案中的全部或部分内容可以通过软件编程实现,其软件程序存储在可读取的存储介质中,存储介质例如:计算机中的硬盘、光盘或软盘。All or part of the technical solutions provided by the above embodiments can be realized by software programming, and the software program is stored in a readable storage medium, such as a hard disk, an optical disk or a floppy disk in a computer.

以上所述仅为本发明的较佳实施例,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the protection of the present invention. within range.

Claims (13)

1.一种执行程序的方法,其特征在于,所述方法包括:1. A method for executing a program, characterized in that the method comprises: 顺序扫描源程序的文本文件中的指令;Sequentially scan the instructions in the text file of the source program; 读取所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块;Read the name of the instruction, the operand of the instruction, the delimiter to which the instruction belongs, and the program block to which the instruction belongs; 计算所述定界符的执行时间;calculating the execution time of said delimiter; 获取所述操作数的存储空间和读写属性;Obtain the storage space and read/write attributes of the operand; 将所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块、所述定界符的执行时间、所述操作数的存储空间和读写属性作为指令信息;The name of the instruction, the operand of the instruction, the delimiter and the program block to which the instruction belongs, the execution time of the delimiter, the storage space of the operand and the read-write attribute are used as the instruction information; 建立串行队列;Create a serial queue; 从所述指令信息的程序块的主程序块为入口,顺序扫描所述指令信息中的定界符包括的指令;From the main program block of the program block of the instruction information as an entry, sequentially scan the instructions included in the delimiter in the instruction information; 将所述定界符作为节点加入到所述串行队列,其中,将所述定界符的执行时间作为所述节点的权重;adding the delimiter as a node to the serial queue, wherein the execution time of the delimiter is used as the weight of the node; 判断所述指令是否为调用CALL指令,如果所述指令为CALL指令,则跳入所述CALL指令调用的程序块,扫描所述程序块中的定界符包括的指令;Judging whether the instruction is to call a CALL instruction, if the instruction is a CALL instruction, then jump into the program block called by the CALL instruction, and scan the instructions included in the delimiter in the program block; 将所述串行队列中的节点存入并行时序图中;storing the nodes in the serial queue into a parallel sequence diagram; 在所述串行队列中,设置指针1指向队头节点,设置指针2指向所述指针1指向的节点的下一个节点;In the serial queue, the pointer 1 is set to point to the team head node, and the pointer 2 is set to point to the next node of the node pointed to by the pointer 1; 根据操作数的存储空间和读写属性,判断所述指针1指向的节点与所述指针2指向的节点是否存在数据依赖关系,如果存在,在所述并行时序图中,在所述指针1指向的节点与所述指针2指向的节点之间加入有向边,方向为所述指针1指向的节点指向所述指针2指向的节点,在所述串行队列中,重新设置所述指针2指向下一个节点;According to the storage space and the read-write attribute of the operand, it is judged whether there is a data dependency relationship between the node pointed to by the pointer 1 and the node pointed to by the pointer 2, and if there is, in the parallel sequence diagram, the node pointed by the pointer 1 A directed edge is added between the node pointed to by the pointer 2 and the node pointed to by the pointer 2, and the direction is that the node pointed to by the pointer 1 points to the node pointed to by the pointer 2, and in the serial queue, the pointer 2 points to next node; 如果不存在,在所述串行队列中,重新设置所述指针2指向下一个节点;If it does not exist, in the serial queue, reset the pointer 2 to point to the next node; 根据所述并行时序图,并行执行所述源程序;Executing the source program in parallel according to the parallel sequence diagram; 其中,所述源程序由一个或多个程序块组成,所述程序块由一个或多个定界符组成,所述定界符由一条或多条指令组成。Wherein, the source program is composed of one or more program blocks, the program block is composed of one or more delimiters, and the delimiter is composed of one or more instructions. 2.如权利要求1所述的方法,其特征在于,所述根据所述串行队列,构造并行时序图之后,所述方法还包括:2. The method according to claim 1, characterized in that, according to the serial queue, after constructing a parallel sequence diagram, the method further comprises: 通过拓扑排序算法对所述并行时序图中的节点进行遍历,将已遍历的节点加入队列中,读取正在遍历的节点的后继节点;traversing the nodes in the parallel sequence diagram through a topological sorting algorithm, adding the traversed nodes to the queue, and reading the successor nodes of the traversed nodes; 从所述队列中查找是否存在所述后继节点的前趋节点,如果存在,则标注所述前趋节点与所述后继节点之间的有向边为冗余边,将所述正在遍历的节点加入所述队列,通过所述拓扑排序算法遍历下一个节点;Find whether there is a predecessor node of the successor node from the queue, if it exists, mark the directed edge between the predecessor node and the successor node as a redundant edge, and the node being traversed Join the queue, and traverse the next node through the topological sorting algorithm; 如果不存在,则将所述正在遍历的节点加入所述队列,通过所述拓扑排序算法遍历下一个节点;If it does not exist, the node being traversed is added to the queue, and the next node is traversed by the topology sorting algorithm; 从所述并行时序图中去除冗余边。Redundant edges are removed from the parallel timing graph. 3.如权利要求1所述的方法,其特征在于,所述根据所述并行时序图,并行执行所述源程序,具体包括:3. The method according to claim 1, wherein said executing said source program in parallel according to said parallel sequence diagram specifically comprises: 将所述并行时序图分解成连通分量;decomposing the parallel timing graph into connected components; 将所述连通分量分配给CPU,由所述CPU执行所述连通分量的节点。The connected components are assigned to a CPU, and the nodes of the connected components are executed by the CPU. 4.如权利要求1所述的方法,其特征在于,所述根据所述并行时序图,并行执行所述源程序,具体包括4. The method according to claim 1, wherein said executing said source program in parallel according to said parallel sequence diagram specifically comprises 将所述并行时序图分解成连通分量;decomposing the parallel timing graph into connected components; 根据节点的权重,查找所述连通分量的关键路径;Finding the critical path of the connected component according to the weight of the node; 根据所述关键路径,从所述连通分量中划分节点,将所述划分的节点分配给CPU,由所述CPU执行所述划分的节点;dividing nodes from the connected components according to the critical path, allocating the divided nodes to a CPU, and executing the divided nodes by the CPU; 将所述连通分量组成新的并行时序图;Composing the connected components into a new parallel sequence graph; 根据节点的权重,从所述新的并行时序图中,寻找关键路径;Finding a critical path from the new parallel sequence diagram according to the weights of the nodes; 根据所述寻找的关键路径,从所述新的并行时序图中分离节点,将所述分离的节点分配给所述CPU,由所述CPU执行所述分离的节点。According to the found critical path, separate nodes from the new parallel sequence diagram, assign the separated nodes to the CPU, and execute the separated nodes by the CPU. 5.一种验证程序结果的方法,其特征在于,所述方法包括:5. A method for verifying program results, characterized in that the method comprises: 根据并行时序图,创建Petri网模型;Create a Petri net model based on the parallel sequence diagram; 在所述Petri网模型中的第一个库节点中设置初始标志;Initial flag is set in the first storehouse node in described Petri net model; 设置指针指向程序执行序列中的第一个节点;Set the pointer to point to the first node in the program execution sequence; 将所述指针指向的节点映射到所述Petri网模型中对应的变迁节点;Mapping the node pointed by the pointer to the corresponding transition node in the Petri net model; 判断所述变迁节点的前库节点中是否存在所述初始标志,如果否,则返回程序结果出错的信息;Judging whether the initial flag exists in the front library node of the transition node, if not, returning the error message of the program result; 如果是,将所述初始标志移入所述变迁节点的后库节点,判断所述程序执行序列是否还存在其他的节点,如果是,设置所述指针指向下一个节点,如果否,返回程序结果正确的信息。If yes, move the initial flag into the back library node of the transition node, judge whether there are other nodes in the program execution sequence, if yes, set the pointer to point to the next node, if not, return the program result is correct Information. 6.如权利要求5所述的方法,其特征在于,所述根据并行时序图,创建Petri网模型,具体包括:6. the method for claim 5, is characterized in that, described according to parallel timing diagram, creates Petri net model, specifically comprises: 将所述并行时序图中的节点转换成Petri网模型中变迁节点;Converting the nodes in the parallel sequence diagram into transition nodes in the Petri net model; 根据所述并行时序图的拓扑结构,连接所述Petri网模型中的变迁节点;According to the topology structure of the parallel sequence diagram, connect the transition nodes in the Petri net model; 简化所述Petri网模型。Simplify the Petri net model. 7.一种执行程序的装置,其特征在于,所述装置包括获取模块、建立模块、构造模块和执行模块:7. A device for executing a program, characterized in that the device includes an acquisition module, an establishment module, a construction module and an execution module: 所述获取模块包括第一扫描单元、读取单元、计算单元和第一获取单元;The acquisition module includes a first scanning unit, a reading unit, a calculation unit and a first acquisition unit; 所述第一扫描单元,用于顺序扫描源程序的文本文件中的指令;The first scanning unit is used to sequentially scan the instructions in the text file of the source program; 所述读取单元,用于读取所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块;The reading unit is configured to read the name of the instruction, the operand of the instruction, the delimiter to which the instruction belongs, and the program block to which the instruction belongs; 所述计算单元,用于计算所述定界符的执行时间;The calculation unit is used to calculate the execution time of the delimiter; 所述第一获取单元,用于获取所述操作数的存储空间和读写属性;The first acquiring unit is configured to acquire the storage space and read/write attributes of the operand; 将所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块、所述定界符的执行时间、所述操作数的存储空间和读写属性作为指令信息;The name of the instruction, the operand of the instruction, the delimiter and the program block to which the instruction belongs, the execution time of the delimiter, the storage space of the operand and the read-write attribute are used as the instruction information; 所述建立模块包括建立单元、第二扫描单元、添加单元和判断单元;The building module includes a building unit, a second scanning unit, an adding unit and a judging unit; 所述建立单元,用于建立串行队列;The establishment unit is used to establish a serial queue; 所述第二扫描单元,用于从所述指令信息的程序块的主程序块为入口,顺序扫描所述指令信息中的定界符包括的指令;The second scanning unit is configured to sequentially scan the instructions included in the delimiter in the instruction information from the main program block of the instruction information program block as an entry; 所述添加单元,用于将所述定界符作为节点加入到所述串行队列,其中,将所述定界符的执行时间作为所述节点的权重;The adding unit is configured to add the delimiter as a node to the serial queue, wherein the execution time of the delimiter is used as the weight of the node; 所述判断单元,用于判断所述指令是否为调用CALL指令,如果所述指令为CALL指令,则跳入所述CALL指令调用的程序块,扫描所述程序块中的定界符包括的指令;The judging unit is used to judge whether the instruction is a call CALL instruction, if the instruction is a CALL instruction, then jump into the program block called by the CALL instruction, and scan the instructions included in the delimiter in the program block ; 所述构造模块包括存储单元、第一设置单元和第一判断单元;The construction module includes a storage unit, a first setting unit and a first judging unit; 所述存储单元,用于将所述串行队列中的节点存入并行时序图中;The storage unit is used to store the nodes in the serial queue into a parallel sequence diagram; 所述第一设置单元,用于在所述串行队列中,设置指针1指向队头节点,设置指针2指向所述指针1指向的节点的下一个节点;The first setting unit is configured to set the pointer 1 to point to the queue head node in the serial queue, and set the pointer 2 to point to the node next to the node pointed to by the pointer 1; 所述第一判断单元,用于根据操作数的存储空间和读写属性,判断所述指针1指向的节点与所述指针2指向的节点是否存在数据依赖关系,如果存在,在所述并行时序图中,在所述指针1指向的节点与所述指针2指向的节点之间加入有向边,方向为所述指针1指向的节点指向所述指针2指向的节点,在所述串行队列中,重新设置所述指针2指向下一个节点;如果不存在,在所述串行队列中,重新设置所述指针2指向下一个节点;The first judging unit is configured to judge whether there is a data dependency relationship between the node pointed to by the pointer 1 and the node pointed to by the pointer 2 according to the storage space and the read/write attribute of the operand, and if so, in the parallel sequence In the figure, a directed edge is added between the node pointed to by the pointer 1 and the node pointed to by the pointer 2, and the direction is that the node pointed to by the pointer 1 points to the node pointed to by the pointer 2, and in the serial queue , reset the pointer 2 to point to the next node; if it does not exist, reset the pointer 2 to point to the next node in the serial queue; 所述执行模块,用于根据所述并行时序图,并行执行所述源程序;The execution module is configured to execute the source program in parallel according to the parallel sequence diagram; 其中,所述源程序由一个或多个程序块组成,所述程序块由一个或多个定界符组成,所述定界符由一条或多条指令组成。Wherein, the source program is composed of one or more program blocks, the program block is composed of one or more delimiters, and the delimiter is composed of one or more instructions. 8.如权利要求7所述的装置,其特征在于,所述装置还包括:8. The device of claim 7, further comprising: 遍历模块,用于通过拓扑排序算法对所述并行时序图中的节点进行遍历,将已遍历的节点加入队列中,读取正在遍历的节点的后继节点;The traversal module is used to traverse the nodes in the parallel sequence diagram through a topology sorting algorithm, add the traversed nodes to the queue, and read the successor nodes of the traversed nodes; 查找模块,用于从所述队列中查找是否存在所述后继节点的前趋节点,如果存在,则标注所述前趋节点与所述后继节点之间的有向边为冗余边,将所述正在遍历的节点加入所述队列,通过所述拓扑排序算法遍历下一个节点;如果不存在,则将所述正在遍历的节点加入所述队列,通过所述拓扑排序算法遍历下一个节点;A search module, configured to search from the queue whether there is a predecessor node of the successor node, and if so, mark the directed edge between the predecessor node and the successor node as a redundant edge, and convert all The node being traversed is added to the queue, and the next node is traversed by the topological sorting algorithm; if it does not exist, the node being traversed is added to the queue, and the next node is traversed by the topological sorting algorithm; 去除模块,用于从所述并行时序图中去除冗余边。A removal module, configured to remove redundant edges from the parallel sequence graph. 9.如权利要求7所述的装置,其特征在于,所述执行模块具体包括:9. The device according to claim 7, wherein the execution module specifically comprises: 第一分解单元,用于将所述并行时序图分解成连通分量;a first decomposing unit, configured to decompose the parallel sequence graph into connected components; 第一分配单元,用于将所述连通分量分配给CPU,由所述CPU执行所述连通分量的节点。A first allocating unit, configured to allocate the connected components to a CPU, and the CPU executes the nodes of the connected components. 10.如权利要求7所述的装置,其特征在于,所述执行模块具体包括10. The device according to claim 7, wherein the execution module specifically includes 第二分解单元,用于将所述并行时序图分解成连通分量;a second decomposing unit, configured to decompose the parallel sequence graph into connected components; 第一查找单元,用于根据所述节点的权重查找所述连通分量的关键路径;a first search unit, configured to search for the critical path of the connected component according to the weight of the node; 划分单元,用于根据所述关键路径,从所述连通分量中划分节点,将所述划分的节点分配给CPU,由所述CPU执行所述划分的节点;A dividing unit, configured to divide nodes from the connected components according to the critical path, assign the divided nodes to a CPU, and execute the divided nodes by the CPU; 组成单元,用于将所述连通分量组成新的并行时序图;a composition unit, configured to form the connected components into a new parallel sequence diagram; 寻找单元,用于根据节点的权重,从所述新的并行时序图中,寻找关键路径;a finding unit, configured to find a critical path from the new parallel sequence diagram according to the weights of the nodes; 分离单元,用于根据所述寻找的关键路径,从所述新的并行时序图中分离节点,将所述分离的节点分配给所述CPU,由所述CPU执行所述分离的节点。A separating unit is configured to separate nodes from the new parallel sequence diagram according to the found critical path, assign the separated nodes to the CPU, and execute the separated nodes by the CPU. 11.一种验证程序结果的装置,其特征在于,所述装置包括:11. A device for verifying program results, characterized in that the device comprises: 创建模块,用于根据并行时序图,创建Petri网模型;Create a module for creating a Petri net model based on a parallel sequence diagram; 第一设置模块,用于在所述Petri网模型中的第一个库节点中设置初始标志;The first setting module is used to set the initial sign in the first library node in the Petri net model; 第二设置模块,用于设置指针指向程序执行序列的第一个节点;The second setting module is used to set the pointer to point to the first node of the program execution sequence; 映射模块,用于将所述指针指向的节点映射到所述Petri网模型中对应的变迁节点;A mapping module, configured to map the node pointed to by the pointer to the corresponding transition node in the Petri net model; 第一判断模块,用于判断所述变迁节点的前库节点中是否存在所述初始标志,如果否,则返回程序结果出错的信息;The first judging module is used to judge whether the initial flag exists in the front library node of the transition node, and if not, return the information that the program result is wrong; 第二判断模块,用于当所述第一判断模块判断的结果为是,将所述初始标志移入所述变迁节点的后库节点,判断所述程序执行序列是否还存在其他的节点,如果是,设置所述指针指向下一个节点,如果否,返回程序结果正确的信息。The second judging module is used to move the initial flag into the back library node of the transition node when the judging result of the first judging module is yes, and judge whether there are other nodes in the program execution sequence, if yes , set the pointer to point to the next node, if not, return the information that the program result is correct. 12.如权利要求11所述的装置,其特征在于,所述创建模块具体包括:12. The device according to claim 11, wherein the creation module specifically comprises: 映射单元,用于将所述并行时序图中的节点转换成Petri网模型中变迁节点;A mapping unit, configured to convert the nodes in the parallel sequence diagram into transition nodes in the Petri net model; 连接单元,用于根据所述并行时序图的拓扑结构,连接所述Petri网模型中的变迁节点;a connection unit, configured to connect transition nodes in the Petri net model according to the topology of the parallel sequence diagram; 简化单元,用于简化所述Petri网模型。A simplification unit is used to simplify the Petri net model. 13.一种执行程序的系统,其特征在于,所述系统包括执行程序的装置和验证程序结果的装置:13. A system for executing a program, characterized in that said system comprises means for executing the program and means for verifying the result of the program: 所述执行程序的装置包括获取模块、建立模块、构造模块和执行模块;The device for executing the program includes an acquisition module, an establishment module, a construction module and an execution module; 所述获取模块包括第一扫描单元、读取单元、计算单元和第一获取单元;The acquisition module includes a first scanning unit, a reading unit, a calculation unit and a first acquisition unit; 所述第一扫描单元,用于顺序扫描源程序的文本文件中的指令;The first scanning unit is used to sequentially scan the instructions in the text file of the source program; 所述读取单元,用于读取所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块;The reading unit is configured to read the name of the instruction, the operand of the instruction, the delimiter to which the instruction belongs, and the program block to which the instruction belongs; 所述计算单元,用于计算所述定界符的执行时间;The calculation unit is used to calculate the execution time of the delimiter; 所述第一获取单元,用于获取所述操作数的存储空间和读写属性;The first acquiring unit is configured to acquire the storage space and read/write attributes of the operand; 将所述指令的名称、所述指令的操作数、所述指令所属的定界符以及所属的程序块、所述定界符的执行时间、所述操作数的存储空间和读写属性作为指令信息;The name of the instruction, the operand of the instruction, the delimiter and the program block to which the instruction belongs, the execution time of the delimiter, the storage space of the operand and the read-write attribute are used as the instruction information; 所述建立模块包括建立单元、第二扫描单元、添加单元和判断单元;The building module includes a building unit, a second scanning unit, an adding unit and a judging unit; 所述建立单元,用于建立串行队列;The establishment unit is used to establish a serial queue; 所述第二扫描单元,用于从所述指令信息的程序块的主程序块为入口,顺序扫描所述指令信息中的定界符包括的指令;The second scanning unit is configured to sequentially scan the instructions included in the delimiter in the instruction information from the main program block of the instruction information program block as an entry; 所述添加单元,用于将所述定界符作为节点加入到所述串行队列,其中,将所述定界符的执行时间作为所述节点的权重;The adding unit is configured to add the delimiter as a node to the serial queue, wherein the execution time of the delimiter is used as the weight of the node; 所述判断单元,用于判断所述指令是否为调用CALL指令,如果所述指令为CALL指令,则跳入所述CALL指令调用的程序块,扫描所述程序块中的定界符包括的指令;The judging unit is used to judge whether the instruction is a call CALL instruction, if the instruction is a CALL instruction, then jump into the program block called by the CALL instruction, and scan the instructions included in the delimiter in the program block ; 所述构造模块包括存储单元、第一设置单元和第一判断单元;The construction module includes a storage unit, a first setting unit and a first judging unit; 所述存储单元,用于将所述串行队列中的节点存入并行时序图中;The storage unit is used to store the nodes in the serial queue into a parallel sequence diagram; 所述第一设置单元,用于在所述串行队列中,设置指针1指向队头节点,设置指针2指向所述指针1指向的节点的下一个节点;The first setting unit is configured to set the pointer 1 to point to the queue head node in the serial queue, and set the pointer 2 to point to the node next to the node pointed to by the pointer 1; 所述第一判断单元,用于根据操作数的存储空间和读写属性,判断所述指针1指向的节点与所述指针2指向的节点是否存在数据依赖关系,如果存在,在所述并行时序图中,在所述指针1指向的节点与所述指针2指向的节点之间加入有向边,方向为所述指针1指向的节点指向所述指针2指向的节点,在所述串行队列中,重新设置所述指针2指向下一个节点;如果不存在,在所述串行队列中,重新设置所述指针2指向下一个节点;The first judging unit is configured to judge whether there is a data dependency relationship between the node pointed to by the pointer 1 and the node pointed to by the pointer 2 according to the storage space and the read/write attribute of the operand, and if so, in the parallel sequence In the figure, a directed edge is added between the node pointed to by the pointer 1 and the node pointed to by the pointer 2, and the direction is that the node pointed to by the pointer 1 points to the node pointed to by the pointer 2, and in the serial queue , reset the pointer 2 to point to the next node; if it does not exist, reset the pointer 2 to point to the next node in the serial queue; 所述执行模块,用于根据所述并行时序图,并行执行所述源程序;The execution module is configured to execute the source program in parallel according to the parallel sequence diagram; 其中,所述源程序由一个或多个程序块组成,所述程序块由一个或多个定界符组成,所述定界符由一条或多条指令组成;Wherein, the source program is composed of one or more program blocks, the program block is composed of one or more delimiters, and the delimiter is composed of one or more instructions; 所述验证程序结果的装置包括创建模块、第一设置模块、第二设置模块、映射模块、第一判断模块和第二判断模块;The device for verifying program results includes a creation module, a first setting module, a second setting module, a mapping module, a first judging module and a second judging module; 所述创建模块,用于根据并行时序图,创建Petri网模型;The creation module is used to create a Petri net model according to the parallel sequence diagram; 所述第一设置模块,用于在所述Petri网模型中的第一个库节点中设置初始标志;The first setting module is used to set an initial flag in the first library node in the Petri net model; 所述第二设置模块,用于设置指针指向程序执行序列的第一个节点;The second setting module is used to set the pointer to point to the first node of the program execution sequence; 所述映射模块,用于将所述指针指向的节点映射到所述Petri网模型中对应的变迁节点;The mapping module is configured to map the node pointed by the pointer to the corresponding transition node in the Petri net model; 所述第一判断模块,用于判断所述变迁节点的前库节点中是否存在所述初始标志,如果否,则返回程序结果出错的信息;The first judging module is used to judge whether the initial flag exists in the front library node of the transition node, and if not, return the error message of the program result; 所述第二判断模块,用于当所述第一判断模块判断的结果为是,将所述初始标志移入所述变迁节点的后库节点,判断所述程序执行序列是否还存在其他的节点,如果是,设置所述指针指向下一个节点,如果否,返回程序结果正确的信息。The second judging module is configured to move the initial flag into the back library node of the transition node when the judging result of the first judging module is yes, and judge whether there are other nodes in the program execution sequence, If yes, set the pointer to point to the next node, if no, return information that the program result is correct.
CN2009100863378A 2009-05-31 2009-05-31 Method for implementing program, method for verifying program result, devices and system Expired - Fee Related CN101571810B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2009100863378A CN101571810B (en) 2009-05-31 2009-05-31 Method for implementing program, method for verifying program result, devices and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2009100863378A CN101571810B (en) 2009-05-31 2009-05-31 Method for implementing program, method for verifying program result, devices and system

Publications (2)

Publication Number Publication Date
CN101571810A CN101571810A (en) 2009-11-04
CN101571810B true CN101571810B (en) 2011-09-14

Family

ID=41231172

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2009100863378A Expired - Fee Related CN101571810B (en) 2009-05-31 2009-05-31 Method for implementing program, method for verifying program result, devices and system

Country Status (1)

Country Link
CN (1) CN101571810B (en)

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102339031B (en) * 2010-07-27 2013-12-25 深圳市合信自动化技术有限公司 Method and device for calling subprogram and PLC (Programmable Logic Controller) control system
CN103092753B (en) * 2012-12-29 2015-08-26 华侨大学 A kind of method PLC instruction catalogue program being converted to ordinary Petri net
CN103116498B (en) * 2013-03-07 2017-06-20 徐国庆 Parallel program rule engine and its implementation
WO2014154016A1 (en) * 2013-03-29 2014-10-02 深圳市并行科技有限公司 Parallel database management system and design scheme
CN103543359B (en) * 2013-10-28 2016-04-13 中国电子科技集团公司第四十一研究所 The implementation method of self-defined test function sequence in a kind of microwave measuring instrument
KR102526104B1 (en) * 2016-03-25 2023-04-27 에스케이하이닉스 주식회사 Data storage device and operating method thereof
CN106227736A (en) * 2016-07-11 2016-12-14 乐视控股(北京)有限公司 A kind of logic flow implementation method based on list structure and device
CN108345470B (en) * 2017-01-24 2021-10-08 阿里巴巴集团控股有限公司 Data processing and storing method and device and electronic equipment
CN108733352B (en) * 2017-04-25 2021-06-11 上海寒武纪信息科技有限公司 Device, method and application for supporting vector ordering
CN109117362B (en) * 2018-06-26 2020-08-25 华东师范大学 A PLC Program Verification System Based on Intermediate Language
CN112445587A (en) * 2019-08-30 2021-03-05 上海华为技术有限公司 Task processing method and task processing device

Also Published As

Publication number Publication date
CN101571810A (en) 2009-11-04

Similar Documents

Publication Publication Date Title
CN101571810B (en) Method for implementing program, method for verifying program result, devices and system
CN103080900B (en) The method of parallelization automatic control program and compiler
Orzan On distributed verification and verified distribution
JP4491026B2 (en) Information processing apparatus, program processing method, and computer program
CN111324577B (en) Yml file reading and writing method and device
CN103914556A (en) Large-scale graph data processing method
GB2580348A (en) Compilation method
KR102114245B1 (en) Graphics state manage apparatus and method
CN112394949B (en) Service version dynamic configuration method for continuous integration
CN106033442A (en) A Parallel Breadth-First Search Method Based on Shared Memory Architecture
CN115269204B (en) Memory optimization method and device for neural network compiling
Forsberg et al. Gpu-accelerated real-time path planning and the predictable execution model
CN112685409B (en) PAAS application service topology generation method and device and readable storage medium
Isaacs et al. Recovering logical structure from Charm++ event traces
CN116755782B (en) Method, device, equipment, storage medium and program product for instruction scheduling
Magdich et al. A MARTE extension for global scheduling analysis of multiprocessor systems
Sampson Process-oriented patterns for concurrent software engineering
Magdich et al. A uml/marte-based design pattern for semi-partitioned scheduling analysis
JP2015095096A (en) Mapreduce job execution system and mapreduce job execution method
CN104932982A (en) Message access memory compiling method and related apparatus
JP6349837B2 (en) Scheduler apparatus, scheduling method therefor, arithmetic processing system, and computer program
JP3930255B2 (en) System specification information processing apparatus, system specification information processing method, and program
KR20140009422A (en) Conservative garbage collecting with concurrent marking and concurrent sweeping for memory management
CN102567845A (en) Online migration method and equipment for running example during combined service evolution
JP2012221147A (en) Computer and resource management method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C17 Cessation of patent right
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20110914

Termination date: 20120531