1

I have installed and include the required packages but it still gives me the error. Here is my code:

\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
    Welcome to TeX.SE! What should that \Begin and \End do in the algorithm? Comment them out/delete them and you can compile without errors ... – Mensch Jul 20 at 15:51
  • @Mensch I want to use begin and end command. It will start a block with bold begin and end it with bold End – Rami Far Jul 20 at 16:29
  • 1
    Hm, but there is no need for a separat begin/end ... Or do you mean to call another procedure defined later on? Without any condition for the starting \Begin/\End an stand-alone \Begin/\End makes syntactical no sense ... Therefore the correct error message ... Please explain better what concret you want to get (how to do that is then another question with perhaps surprising solutions ...) – Mensch Jul 20 at 16:41
  • @Mensch \Begin and \End command is provided by algorithmx package I have read the manual. I want to use it to tell from here my parallel region is started – Rami Far Jul 20 at 17:02
  • 1
    @RamiFar please post a full minimal example instead of this sniplet, then we all know what we are dealing with (preamble and document class). – daleif Jul 20 at 17:29
0

Well, if I understand you right one possibility for you is to define a new procedure like

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

You can use for example

\State \Call{parallelProcess}{mesh}

to call thi procedure in your algorithm.

Please see the complete 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}

and its result:

resulting algorithmn

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.