Parfor problem --- "Array construction from ByteBuffer Threw an exception"

Hi! I run my code using the 'parfor' function BUT receive an error message:
  • Array construction from ByteBuffer Threw an exception.
I am wondering what does this message mean in simple language? Any simple example could be great!
Thanks for your help!

6 件のコメント

Edric Ellis
Edric Ellis 2021 年 7 月 21 日
This is an unexpected internal error. Can you provide simple reproduction steps? (Or you could contact MathWorks support directly for help with this).
Jiashun Wu
Jiashun Wu 2021 年 7 月 21 日
Thanks for your comments.
My idea is quite simple, I want to separate table records into different groups (in cells) based on the value of a variable (e.g., "varname_a"), so that I can deal with different specfic records differently. As there are millions of rows with thousands of different variable values, I would like to use the parallel pool to speed up this approach.
Let me try to write this structure in a general format:
Tablename_Cell = {};
K = table(unique(Tablename.varname_a), ...
'VariableNames', {'varname_a'});
A_number = 1000;
O = parpool('local', Num);
parfor i = 1:A_number
Tablename_Cell{i, 1} = Tablename( ...
find(Tablename.varname_a == K.varname_a(i)) , :);
% Some other codes afterwards --- But even just keep the code
% above would receive the error message "Array construction
% from ByteBuffer Threw an exception."
end
Walter Roberson
Walter Roberson 2021 年 7 月 21 日
Did you time findgroups()?
Jiashun Wu
Jiashun Wu 2021 年 7 月 21 日
@Walter Roberson Thanks for you note BUT not sure what do you mean...
"find" is the Matlab function find.
Walter Roberson
Walter Roberson 2021 年 7 月 21 日
"I want to separate table records into different groups (in cells) based on the value of a variable (e.g., "varname_a"),"
G = findgroups(varname_a) ;
Tablename_cell = splitapply(@(x) {x}, Tablensme, G);
Jiashun Wu
Jiashun Wu 2021 年 7 月 25 日
@Walter Roberson Thanks again for your note.
My aim is to use 'parfor' to help separate my table into sub-groups, without imposing any summary statistics. In other words, somewhere like improving the code in https://www.mathworks.com/matlabcentral/answers/535864-how-do-you-split-a-table-into-sub-tables-based-on-entries-in-a-specific-column.
Anyway, I have already improved my code for better efficiency while keeping a tradtional 'for' approach.

サインインしてコメントする。

 採用された回答

Alvaro
Alvaro 2022 年 12 月 1 日
編集済み: Alvaro 2022 年 12 月 1 日

0 投票

The following code runs with no issues in my version of MATLAB R2022b.
load patients
% Create test table
Tablename = table(Gender(1:5), Height(1:5), 'VariableNames', {'Gender', 'Height'});
clearvars -except Tablename
Tablename_Cell = {};
K = table(unique(Tablename.Gender), ...
'VariableNames', {'Gender'});
A_number = 2;
parfor i = 1:A_number
Tablename_Cell{i} = Tablename(find(strcmp(Tablename.Gender, K.Gender(i))),:);
% Some other codes afterwards --- But even just keep the code
% above would receive the error message "Array construction
% from ByteBuffer Threw an exception."
end
I did switch from using == to strcmp since I got the error
Operator '==' is not supported for operands of type 'cell'.
but I believe everything else is the same. Consider trying Bowei's suggestion of using a for loop with a dummy table to determine whether parfor is the cause of the issue.
I would also take another look at the documentation that you linked
Functions like splitapply already include parallelization as part of their extended capabilities.
https://www.mathworks.com/help/matlab/ref/splitapply.html#refsect-extended-capabilities

その他の回答 (1 件)

Bowei Li
Bowei Li 2022 年 8 月 18 日

0 投票

Hi, I run into this error when using parfor as well. I found there was a undefined variable in my parfor loop. To check it, you may change your parfor to for, run it, and see what it says.

カテゴリ

ヘルプ センター および File Exchange で Programming についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 7 月 20 日

編集済み:

2022 年 12 月 1 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by