isKey
説明
例
ワーカー上でシミュレーションを実行し、クライアント上でジョブのデータ ストレージを取得します。データ ストレージは、キーと値のエントリをもつ ValueStore オブジェクトです。指定したキーがこのオブジェクト内に存在するかどうかを確認します。
次のシミュレーションでは、乱数行列の逆行列を求め、結果を ValueStore オブジェクトに保存します。
type workerInvCodefunction workerInvCode(models)
% Get the ValueStore of the current job
store = getCurrentValueStore;
for i = 1:numel(models)
% Store simulation results in the ValueStore object
pause(1);
key = strcat("result_",num2str(i));
store(key) = inv(rand(models(i)));
end
end
既定のクラスター プロファイルを使用して、ワーカー上でバッチ ジョブを実行します。
models = [4,8,32,20];
c = parcluster;
job = batch(c,@workerInvCode,0,{models});
wait(job);クライアント上の ValueStore オブジェクトを取得します。
store = job.ValueStore;
このオブジェクトのキーを表示します。
keys(store)
ans = 4×1 string
"result_1"
"result_2"
"result_3"
"result_4"
以下の指定したキーが ValueStore オブジェクト内に存在するかどうかを確認します。
TF = isKey(store,["result_2", "result_5", "result_3"])
TF = 1×3 logical array
1 0 1
プロセス ワーカーの並列プール上でシミュレーションを実行し、クライアント上のファイル ストレージを取得します。ファイル ストレージは、キーとファイルのエントリをもつ FileStore オブジェクトです。指定したキーがこのオブジェクト内に存在するかどうかを確認します。
次のシミュレーションでは、乱数行列の平均と標準偏差を求め、結果を FileStore オブジェクトに保存します。
type workerStatsCodefunction workerStatsCode(models)
% Get the FileStore of the current job
store = getCurrentFileStore;
for i = 1:numel(models)
% Compute the average and standard deviation of random matrices
A = rand(models(i));
M = mean(A);
S = std(A);
% Save simulation results in temporary files
sourceTempFile = strcat(tempname("C:\myTempFolder"),".mat");
save(sourceTempFile,"M","S");
% Copy files to FileStore object as key-file pairs
key = strcat("result_",num2str(i));
copyFileToStore(store,sourceTempFile,key);
end
end
プロセス ワーカーの並列プールを起動します。
pool = parpool('Processes');Starting parallel pool (parpool) using the 'Processes' profile ... Connected to the parallel pool (number of workers: 6).
このプールの FileStore を取得します。
store = pool.FileStore;
プール上でシミュレーションを実行します。
models = [4,8,32,20]; future = parfeval(@workerStatsCode,0,models); wait(future);
FileStore オブジェクトのキーを表示します。
keys(store)
以下の指定したキーが FileStore オブジェクト内に存在するかどうかを確認します。
TF = isKey(store,["result_2", "result_5", "result_3"])
入力引数
MATLAB クライアントとワーカーで共有されるデータ ストレージまたはファイル ストレージ。ValueStore オブジェクトまたは FileStore オブジェクトとして指定します。
検索対象とするキー。文字ベクトル、string スカラー、string 配列、もしくは文字ベクトルまたは string の cell 配列として指定します。
バージョン履歴
R2022a で導入
参考
ValueStore | FileStore | keys | remove | put | get | copyFileToStore | copyFileFromStore
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)