समांतर मोड में चलते समय वैश्विक चर के लिए क्या होता है?MATLAB: समांतर मोड में चलते समय वैश्विक चर के लिए क्या होता है?
मेरे पास एक वैश्विक चर है, "to_be_optimized_parameterIndexSet", जो इंडेक्स का वेक्टर है जिसे gamultiobj का उपयोग करके अनुकूलित किया जाना चाहिए और मैंने अपना मान केवल मुख्य स्क्रिप्ट (कहीं और नहीं) में सेट किया है।
मेरा कोड सीरियल मोड में ठीक से काम करता है लेकिन जब मैं समानांतर मोड पर स्विच करता हूं ("मैटलबूल ओपन" का उपयोग करके और 'गैओपेटिमसेट' के लिए उचित मान निर्धारित करता है) उल्लिखित वैश्विक चर फिटनेस फ़ंक्शन और कारणों में खाली हो जाता है (= []) इस त्रुटि:
??? Error using ==> parallel_function at 598
Error in ==> PF_gaMultiFitness at 15 [THIS LINE: constants(to_be_optimized_parameterIndexSet) = individual;]
In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> fcnvectorizer at 17
parfor (i = 1:popSize)
Error in ==> gamultiobjMakeState at 52
Score =
fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,numObj,options.SerialUserFcn);
Error in ==> gamultiobjsolve at 11
state = gamultiobjMakeState(GenomeLength,FitnessFcn,output.problemtype,options);
E rror in ==> gamultiobj at 238
[x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...
Error in ==> PF_GA_mainScript at 136
[x, fval, exitflag, output] = gamultiobj(@(individual)PF_gaMultiFitness(individual, initialConstants), ...
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
मुझे यकीन है कि मैं इस वैश्विक चर हर जगह और नहीं बदल दिया है करने के लिए सभी कोड की जाँच कर ली।
मेरे पास क्वाड-कोर प्रोसेसर है।
बग कहां है? कोई उपाय?
संपादित करें 1: मुख्य लिपि में MATLAB कोड:
clc
clear
close all
format short g
global simulation_duration % PF_gaMultiFitness will use this variable
global to_be_optimized_parameterIndexSet % PF_gaMultiFitness will use this variable
global IC stimulusMoment % PF_gaMultiFitness will use these variables
[initialConstants IC] = oldCICR_Constants; %initialize state
to_be_optimized_parameterIndexSet = [21 22 23 24 25 26 27 28 17 20];
LB = [ 0.97667 0.38185 0.63529 0.046564 0.23207 0.87484 0.46014 0.0030636 0.46494 0.82407 ];
UB = [1.8486 0.68292 0.87129 0.87814 0.66982 1.3819 0.64562 0.15456 1.3717 1.8168];
PopulationSize = input('Population size? ') ;
GaTimeLimit = input('GA time limit? (second) ');
matlabpool open
nGenerations = inf;
options = gaoptimset('PopulationSize', PopulationSize, 'TimeLimit',GaTimeLimit, 'Generations', nGenerations, ...
'Vectorized','off', 'UseParallel','always');
[x, fval, exitflag, output] = gamultiobj(@(individual)PF_gaMultiFitness(individual, initialConstants), ...
length(to_be_optimized_parameterIndexSet),[],[],[],[],LB,UB,options);
matlabpool close
some other piece of code to show the results...
फिटनेस फंक्शन, "PF_gaMultiFitness" की MATLAB कोड:
function objectives =PF_gaMultiFitness(individual, constants)
global simulation_duration IC stimulusMoment to_be_optimized_parameterIndexSet
%THIS FUNCTION RETURNS MULTI OBJECTIVES AND PUTS EACH OBJECTIVE IN A COLUMN
constants(to_be_optimized_parameterIndexSet) = individual;
[smcState , ~, Time]= oldCICR_CompCore(constants, IC, simulation_duration,2);
targetValue = 1; % [uM]desired [Ca]i peak concentration
afterStimulus = smcState(Time>stimulusMoment,14); % values of [Ca]i after stimulus
peak_Ca_value = max(afterStimulus); % smcState(:,14) is [Ca]i
if peak_Ca_value < 0.8 * targetValue
objectives(1,1) = inf;
else
objectives(1, 1) = abs(peak_Ca_value - targetValue);
end
pkIDX = peakFinder(afterStimulus);
nPeaks = sum(pkIDX);
if nPeaks > 1
peakIndexes = find(pkIDX);
period = Time(peakIndexes(2)) - Time(peakIndexes(1));
objectives(1,2) = 1e5* 1/period;
elseif nPeaks == 1 && peak_Ca_value > 0.8 * targetValue
objectives(1,2) = 0;
else
objectives(1,2) = inf;
end
end
यह कहता है, "इसके अतिरिक्त, आप पारदर्शी लूप के शरीर के भीतर वैश्विक चर या लगातार चर परिभाषित नहीं कर सकते हैं। मैं ग्लोबल्स के उपयोग से सावधान रहना भी सुझाव दूंगा क्योंकि श्रमिकों पर वैश्विक मूल्यों में परिवर्तन स्थानीय वैश्विक मूल्यों में स्वचालित रूप से प्रतिबिंबित नहीं होते हैं। " हालांकि, मैं नहीं बराबर-के लिए छोरों में "वैश्विक चर को परिभाषित" कर रहा हूँ और मैं ग्राहक पर workers.I परिभाषित वैश्विक चर में वैश्विक चर का मान नहीं बदल दिया है और सिर्फ कार्यकर्ताओं में उन्हें इस्तेमाल किया। –
वैसे, वैश्विक चर को संशोधित इतना है कि वे स्पष्ट रूप से पारित कर दिया हो के बाद, समस्या का समाधान, लेकिन अभी तक यह MATLAB मदद है कि आप नहीं श्रमिकों के लिए वैश्विक चर के माध्यम से जानकारी भेज सकते हैं में नहीं लिखा है। –
स्पष्ट रूप से उन्हें पारित करने के लिए आप अपने कोड को कैसे संशोधित करते हैं? मैं एक वैश्विक विन्यास (फ़िग्स procude है कि क्या, फाइल सिस्टम के लिए फ़ाइलों को लिखने के लिए है कि क्या) एक वैश्विक struct में जमा हो जाती है कि मैं सिर्फ कार्यकर्ताओं पर पढ़ना चाहते है, यही कारण है कि मैं पूछ रहा हूँ है। – Ronny