error using parallel.p​ool.consta​nt/get value

2 次查看(过去 30 天)
  1. so this is my code (not sure about function handle in parfeval). The error I get is on line 11. I dont understand the error
poolobj=parpool('my_cluster',8);
[up, op]=ndgri(1e-3:1e-2:1,1e-3:1e-2:1);
up=reshape(up, [1,size(up,1)*size(up,2)]);
up=reshape(up, [1,size(up,1)*size(up,2)]);
z=rand(5,5e3);
addAttachedFiles('<path to my function/cores_random.m');%%to add the function files to workers on the pool
C1=parallel.pool.Constant(z);%%use parallel.pool.Constant to copy these variables into workers
U2=parallel.pool.Constant(up);
O2=parallel.pool.Constant(op);
for i=1:size(up,2)
f1(i)=parfeval(poolobj,@cores_random,3,U2.value(i),O2.Value(i),C1.Value(1,:)); %%line 11
f2(i)=parfeval(poolobj,@cores_random,3,U2.value(i),O2.Value(i),C1.Value(2,:));
f3(i)=parfeval(poolobj,@cores_random,3,U2.value(i),O2.Value(i),C1.Value(3,:));
f4(i)=parfeval(poolobj,@cores_random,3,U2.value(i),O2.Value(i),C1.Value(4,:));
f5(i)=parfeval(poolobj,@cores_random,3,U2.value(i),O2.Value(i),C1.Value(5,:));
end
for j=1:size(up,2):-1:1
[idx1,u1,o1,ep1]=fetchNext(f1);
[idx2,u2,o2,ep2]=fetchNext(f2);
[idx3,u3,o3,ep3]=fetchNext(f3);
[idx4,u4,o4,ep4]=fetchNext(f4);
[idx5,u5,o5,ep5]=fetchNext(f5);
end
I got an error
{Error using paralle.pool.Constant/get.Value The value of a parallel.pool.Constant is only available on the workers.
Error in main_parallel_norm (line 11)
f1(i)=parfeval(poolobj,@cores_random,3,U2.value(i),O2.Value(i),C1.Value(1,:));
the function cores_random is as the following:
[uu,oo,ep]=cores_random(up,op,z)
%%doing some calculations here
%%z is of size 1*1e3
%%up is scalar op is scalar
end
  2 个评论
Walter Roberson
Walter Roberson 2020-10-5
Is there a particular reason to ask for 8 cores but use cycles of 5 futures?
Muna Tageldin
Muna Tageldin 2020-10-8
yes since the output depends on differnt rows of C1.value
On other words the original function is like this:
for i=1:size(up,2)
[u1(1,i),oo(1,i),ep(1,i)]=cores_random(up(i),op(i),z(1,:))
[u1(2,i),oo(2,i),ep(2,i)]=cores_random(up(i),op(i),z(2,:))
[u1(3,i),oo(3,i),ep(3,i)]=cores_random(up(i),op(i),z(3,:))
end

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-10-2
poolobj=parpool('my_cluster',8);
[up, op]=ndgri(1e-3:1e-2:1,1e-3:1e-2:1);
up=reshape(up, [1,size(up,1)*size(up,2)]);
up=reshape(up, [1,size(up,1)*size(up,2)]);
z=rand(5,5e3);
addAttachedFiles('<path to my function/cores_random.m');%%to add the function files to workers on the pool
C1=parallel.pool.Constant(z);%%use parallel.pool.Constant to copy these variables into workers
U2=parallel.pool.Constant(up);
O2=parallel.pool.Constant(op);
for i=1:size(up,2)
f1(i) = parfeval(poolobj,@cores_random, 2, i, 1); %%line 11
f2(i) = parfeval(poolobj,@cores_random, 2, i, 2);
f3(i) = parfeval(poolobj,@cores_random, 2, i, 3);
f4(i) = parfeval(poolobj,@cores_random, 2, i, 4);
f5(i) = parfeval(poolobj,@cores_random, 2, i, 5);
end
for j=1:size(up,2):-1:1
[idx1,u1,o1,ep1]=fetchNext(f1);
[idx2,u2,o2,ep2]=fetchNext(f2);
[idx3,u3,o3,ep3]=fetchNext(f3);
[idx4,u4,o4,ep4]=fetchNext(f4);
[idx5,u5,o5,ep5]=fetchNext(f5);
end
function [uu,oo,ep] = cores_random(i, zidx)
up = U2.Value(i)
op = O2.Value(i);
z = C1.Value(zidx,:);
%%doing some calculations here
%%z is of size 1*1e3
%%up is scalar op is scalar
end
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by