bugGNU Octave - Bugs: bug #64813, [octave forge] (parallel)...

 
 

bug #64813: [octave forge] (parallel) pararrayfun does not work with inline functions

Submitter:  Umberto <umbe1987>
Submitted:  Wed 25 Oct 2023 10:33:48 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Documentation
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * 5.2.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 25 Oct 2023 09:03:16 PM UTC, comment #6: 

OK coming up to speed now.  So the wiki isn't the official package docs, and even the package doc link there is broken, when it should point to
https://octave.sourceforge.io/parallel/4.0.2/package_doc/

I don't know where or how that examples document was sourced, and if it can be updated, but I've cc'd the package maintainer.

Nicholas Jankowski <nrjank>
Group Member
Wed 25 Oct 2023 07:26:11 PM UTC, comment #5: 

Sorry for the silly question but the example is a pdf file, how or where should I edit it?

https://wiki.octave.org/wiki/images/e/e9/Examples_of_how_to_use_parrarrayfun.pdf

BTW thanks for the package and for reopening the bug. If I have time and understand how to do it, I would be glad to modify the example.

Umberto <umbe1987>
Wed 25 Oct 2023 06:27:41 PM UTC, comment #4: 

A fair point. I have reopened the report and changed it to the documentation group.  The example is on the wiki so it’s easy enough to change if you havesuggestions for correction.

Nicholas Jankowski <nrjank>
Group Member
Wed 25 Oct 2023 06:20:34 PM UTC, comment #3: 

Might I suggest that this is a bug in the documentation? If running an example from the docs throws an error, then the documentation is wrong and must be fixed.

Closing this issue basically means you don’t care about users being able to use your package.

Anonymous
Wed 25 Oct 2023 03:57:06 PM UTC, comment #2: 

Glad you were able to figure it out and thanks for the follow-up report.  

Adjusting title and closing bug report. It can be reopened if we think that it’s worth keeping the inline function limitation issue as an active task to figure out how to address.

Nicholas Jankowski <nrjank>
Group Member
Wed 25 Oct 2023 01:11:44 PM UTC, comment #1: 

I figured out what was the problem but I don't know how to close this issue.

Thanks to this post in the GNU Octave discourse group, I understood that:

> The way the “parallel” package works in Octave is that it spawns various “independent” instances of Octave and runs the given code in all of those. For this to work correctly, all necessary functions must be accessible in all of those instances. If I understand your code correctly, you define myFun inline. That way it will only be defined in the “main” instance. Move that function to a dedicated file and store it in a place that is in the load path of all instances. (Maybe use .octaverc to add it to your default load path.)


So basically I had to move my function definition in a separate file "myfun.m" (as also suggested by user Cris Luengo in the comments to my question), and move this file in a folder which is in Octave load path.

To do this, I have create a new dedicated folder ("~/octave/custom_funcs"), and added this to the load path with addpath("~/octave/custom_funcs").

Hope this will be helpful for anybody.

Umberto <umbe1987>
Wed 25 Oct 2023 10:33:48 AM UTC, original submission:  

I am testing the pararrayfun function of the parallel package using the official example at this link: https://wiki.octave.org/wiki/images/e/e9/Examples_of_how_to_use_parrarrayfun.pdf

When running the code, I get the following error:


could not save variable.
error: 'myfun' undefined near line 1 column 6
execution error
error: __parcellfun_get_next_result__: could not receive result


The code I am testing is this one (taken from the aforementioned example):


# In this script 4 ways of calculating the values of a one-dimensional function
# are compared, the time taken by each way is measured and it is verified that
# there are no discrepancies in the results.
pkg load parallel

nmax = 10000; # Number of points where the function is calculated

function [a,b] = myfun(n); # Function used in this test
  a = pi*(n-2)/n;
  f = @(x) (cos(x).^n + sin(x).^(n-1));
  b = quadgk(f,0,a);
endfunction

# Fist method, using a for loop, defining the function to calculate
# within the loop.
tic
for n = 1:nmax;
  a1(n) = pi*(n-2)/n;
  b1(n) = quadgk(@(x) (cos(x).^n + sin(x).^(n-1)),0,a1(n));
endfor
t1 = toc

# Second method, using a for loop and calling "myfun"
tic
for n = 1:nmax
  [a2(n),b2(n)] = myfun(n);
endfor
t2= toc

# Third method, using arrayfun to call "myfun"
tic
ni = 1:nmax;
[a3,b3] = arrayfun("myfun",ni);
t3 = toc

# Forth method, using parrayfun to call "myfun"
tic
ni = 1:nmax;
[a4,b4] = pararrayfun(4,@(n) myfun(n),ni);
t4 = toc

# Are discrepancies in the results?
discrepancies_1 = max(a2-a1) + max(b2-b1) + max(a3-a1)
discrepancies_2 = max(b3-b1) + max(a4-a1) + max(b4-b1)


System info in the attached image ("system_info.png").

Umberto <umbe1987>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #55269:  system_info.png added by umbe1987 (59KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by nrjank
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by umbe1987 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-10-25 nrjank Carbon-Copy- Added i7tiol
    2023-10-25 nrjank Item GroupUnexpected Error or Warning Documentation
        Open/ClosedClosed Open
    2023-10-25 nrjank StatusNone Confirmed
        Open/ClosedOpen Closed
        Summarypararrayfun of the parallel package does not work when using the official example [octave forge] (parallel) pararrayfun does not work with inline functions
    2023-10-25 umbe1987 Attached File- Added system_info.png, #55269

    Back to the top

    Powered by Savane 3.13-f762.
    Corresponding source code