Parfor problem --- "Array construction from ByteBuffer Threw an exception"
51 次查看(过去 30 天)
显示 更早的评论
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 个评论
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);
采纳的回答
Alvaro
2022-12-1
编辑:Alvaro
2022-12-1
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
0 个评论
更多回答(1 个)
Bowei Li
2022-8-18
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!