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

2 vues (au cours des 30 derniers jours)
Muna Tageldin
Muna Tageldin le 2 Oct 2020
Commenté : Muna Tageldin le 8 Oct 2020
  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 commentaires
Walter Roberson
Walter Roberson le 5 Oct 2020
Is there a particular reason to ask for 8 cores but use cycles of 5 futures?
Muna Tageldin
Muna Tageldin le 8 Oct 2020
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

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Oct 2020
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 commentaires
Walter Roberson
Walter Roberson le 4 Oct 2020
Are you getting any succesful outputs ?
Muna Tageldin
Muna Tageldin le 5 Oct 2020
no output

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Parallel Computing Fundamentals dans Help Center et File Exchange

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by