未定义控制序列。\Begin 在 algorithmx 包中

未定义控制序列。\Begin 在 algorithmx 包中

我已经安装并包含了所需的软件包,但仍然出现错误。这是我的代码:

\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{algorithm}
    \caption{Mesh Reader}\label{reader}
    \begin{algorithmic}[1]
        \Procedure{mesh\_reader}{}
        \State chunk\_size = rows/total threads
        \Begin
        \State Parallel region   
        \For {each row in mesh}
        \State create node object
        \State assign coordinates of node
        \EndFor
        \End
        \For{ each Element in mesh}
        \If {Element is of \textbf{EDGE} type}
        \State create Edge object
        \State assign node id and other properties to Edge
        \State add Edge object to \textbf{Element list}
        \If{Edge lies on Dirichlet boundary}
        \State Add Edge node id to Dirichlet boundary list
        \EndIf
        \ElsIf{Element is of $\Delta$ type}
        \State create Triangle object
        \State assign node id and other properties to $\Delta$
        \State add $\Delta$ object to \textbf{Element list}
        \EndIf
        \EndFor
        \EndProcedure
    \end{algorithmic}
\end{algorithm}

答案1

好吧,如果我理解正确的话,一种可能性就是定义一个新的程序,比如

    \Procedure{parallelProcess}{mesh}
    \State Parallel region   
    \For {each row in mesh}
    \State create node object
    \State assign coordinates of node
    \EndFor
    \EndProcedure

例如,您可以使用

\State \Call{parallelProcess}{mesh}

在你的算法中调用这个过程。

请参阅完整的 MWE

\documentclass{article}

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
\begin{algorithm}
    \caption{Mesh Reader}\label{reader}
    \begin{algorithmic}[1]
        \Procedure{parallelProcess}{mesh} % <===========================
        \State Parallel region   
        \For {each row in mesh}
        \State create node object
        \State assign coordinates of node
        \EndFor
        \EndProcedure
        \Procedure{mesh\_reader}{}
        \State chunk\_size = rows/total threads
        \State \Call{parallelProcess}{mesh} % <=========================
        \For{ each Element in mesh}
        \If {Element is of \textbf{EDGE} type}
        \State create Edge object
        \State assign node id and other properties to Edge
        \State add Edge object to \textbf{Element list}
        \If{Edge lies on Dirichlet boundary}
        \State Add Edge node id to Dirichlet boundary list
        \EndIf
        \ElsIf{Element is of $\Delta$ type}
        \State create Triangle object
        \State assign node id and other properties to $\Delta$
        \State add $\Delta$ object to \textbf{Element list}
        \EndIf
        \EndFor
        \EndProcedure
    \end{algorithmic}
\end{algorithm}
\end{document}

及其结果:

由此产生的算法

相关内容