changeset 28517:6e8a9845d118

Add 'spmd' as interpreter keyword for Matlab compatibility (bug #58676). * op-kw-docs: Document 'spmd', 'endspmd' keywords. * lex.ll (base_lexer::make_keyword_token): Add case statements for 'spmd', 'endspmd'. Code is not correct, but something is required to prevent segfault. * oct-parse.yy: Add SPMD token type. * oct-parse.yy (end_token_as_string): Add case statement for 'endspmd'. * octave.gperf: Add endspmd_kw, spmd_kw to enum octave_kw_id. Add declarations to octave_kw struct for endspmd, spmd. * token.h: Add spmd_end to enm end_tok_type.
author Rik <rik@octave.org>
date Tue, 30 Jun 2020 09:34:14 -0700
parents 70d155283f33
children b8ab8b58547d
files libinterp/op-kw-docs libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/octave.gperf libinterp/parse-tree/token.h
diffstat 5 files changed, 56 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/op-kw-docs	Mon Jun 29 15:12:39 2020 -0400
+++ b/libinterp/op-kw-docs	Tue Jun 30 09:34:14 2020 -0700
@@ -572,6 +572,13 @@
 Mark the end of a properties block in a classdef definition.
 @seealso{properties}
 @end deftypefn
+endspmd
+@c libinterp/parse-tree/oct-parse.yy
+-*- texinfo -*-
+@deftypefn {} {} endparfor
+Mark the end of an spmd block.  See @code{spmd} for an example.
+@seealso{spmd, parfor}
+@end deftypefn
 endswitch
 @c libinterp/parse-tree/oct-parse.yy
 -*- texinfo -*-
@@ -732,6 +739,31 @@
 Return from a function.
 @seealso{function}
 @end deftypefn
+spmd
+@c libinterp/parse-tree/oct-parse.yy
+-*- texinfo -*-
+@deftypefn  {} {} spmd
+@deftypefnx {} {} spmd (@var{n})
+@deftypefnx {} {} spmd (@var{m}, @var{n})
+Begin a block of statements which may execute in parallel across multiple
+workers.
+
+If Octave has a parallel processing pool enabled, the block of code will be
+executed in parallel across all of the pool's workers.  Otherwise, @code{spmd}
+has no effect and the statements are processed as normal code by the main
+Octave interpreter.
+
+If called with one additional argument @var{n} then use exactly @var{n} workers
+from the pool.  If called with two arguments @var{m}, @var{n} then use a
+minimum of @var{m} workers and a maximum of @var{n} workers from the parallel
+pool.
+
+@strong{Warning:} parallel processing pools are currently unimplemented in
+Octave; @code{spmd} currently does nothing, but is included to avoid breaking
+existing @sc{matlab} code.
+
+@seealso{parfor}
+@end deftypefn
 switch
 @c libinterp/parse-tree/oct-parse.yy
 -*- texinfo -*-
--- a/libinterp/parse-tree/lex.ll	Mon Jun 29 15:12:39 2020 -0400
+++ b/libinterp/parse-tree/lex.ll	Tue Jun 30 09:34:14 2020 -0700
@@ -2763,7 +2763,6 @@
         m_at_beginning_of_statement = true;
         break;
 
-
       case for_kw:
       case parfor_kw:
       case while_kw:
@@ -2844,6 +2843,20 @@
           }
         break;
 
+      /* Unimplementd 'spmd' keyword for Matlab compatibility only.
+         FIXME: Allow spmd statement, but treat as no-op, bug #58676. */
+      case spmd_kw:
+        /* m_at_beginning_of_statement = true; */
+        break;
+
+      case endspmd_kw:
+        /*
+        tok_val = new token (endspmd_kw, token::spmd_end, m_tok_beg,
+                             m_tok_end);
+        m_at_beginning_of_statement = true;
+        */
+        break;
+
       case magic_file_kw:
         {
           if ((m_reading_fcn_file || m_reading_script_file
--- a/libinterp/parse-tree/oct-parse.yy	Mon Jun 29 15:12:39 2020 -0400
+++ b/libinterp/parse-tree/oct-parse.yy	Tue Jun 30 09:34:14 2020 -0700
@@ -205,6 +205,7 @@
 %token <tok_val> END
 %token <tok_val> DQ_STRING SQ_STRING
 %token <tok_val> FOR PARFOR WHILE DO UNTIL
+%token <tok_val> SPMD
 %token <tok_val> IF ELSEIF ELSE
 %token <tok_val> SWITCH CASE OTHERWISE
 %token <tok_val> BREAK CONTINUE FUNC_RET
@@ -2455,6 +2456,10 @@
         retval = "endproperties";
         break;
 
+      case token::spmd_end:
+        retval = "endspmd";
+        break;
+
       case token::switch_end:
         retval = "endswitch";
         break;
--- a/libinterp/parse-tree/octave.gperf	Mon Jun 29 15:12:39 2020 -0400
+++ b/libinterp/parse-tree/octave.gperf	Tue Jun 30 09:34:14 2020 -0700
@@ -51,6 +51,7 @@
   endmethods_kw,
   endparfor_kw,
   endproperties_kw,
+  endspmd_kw,
   endswitch_kw,
   endwhile_kw,
   enumeration_kw,
@@ -69,6 +70,7 @@
   properties_kw,
   return_kw,
   set_kw,
+  spmd_kw,
   switch_kw,
   try_kw,
   until_kw,
@@ -102,6 +104,7 @@
 endmethods, END, endmethods_kw
 endparfor, END, endparfor_kw
 endproperties, END, endproperties_kw
+endspmd, END, endspmd_kw
 endswitch, END, endswitch_kw
 endwhile, END, endwhile_kw
 enumeration, ENUMERATION, enumeration_kw
@@ -118,6 +121,7 @@
 properties, PROPERTIES, properties_kw
 return, FUNC_RET, return_kw
 set, SET, set_kw
+spmd, SPMD, spmd_kw
 switch, SWITCH, switch_kw
 try, TRY, try_kw
 until, UNTIL, until_kw
--- a/libinterp/parse-tree/token.h	Mon Jun 29 15:12:39 2020 -0400
+++ b/libinterp/parse-tree/token.h	Tue Jun 30 09:34:14 2020 -0700
@@ -65,6 +65,7 @@
       switch_end,
       try_catch_end,
       unwind_protect_end,
+      spmd_end,
       while_end,
     };