中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

做網(wǎng)站顯示上次登錄時間代碼手機(jī)百度搜索app

做網(wǎng)站顯示上次登錄時間代碼,手機(jī)百度搜索app,做電腦網(wǎng)站步驟,電商設(shè)計工作職責(zé)一. 內(nèi)容簡介 matlab多線程,parfor循環(huán)進(jìn)度,matlab互斥鎖 二. 軟件環(huán)境 2.1 matlab 2022b 2.2代碼鏈接 https://gitee.com/JJW_1601897441/csdn 三.主要流程 3.1 matlab多線程 有好幾種,最簡單的,最好理解的就是parfor&am…

一. 內(nèi)容簡介

matlab多線程,parfor循環(huán)進(jìn)度,matlab互斥鎖

二. 軟件環(huán)境

2.1 matlab 2022b

2.2代碼鏈接

https://gitee.com/JJW_1601897441/csdn

三.主要流程

3.1 matlab多線程

有好幾種,最簡單的,最好理解的就是parfor,就拿那個為例子了,使用情況就是每一個for循環(huán)之前不能依賴關(guān)系,每輪計算都是獨(dú)立的這種,才可以用parfor,不同版本不太一樣,老版限制好像更多一些

parfor i = 1:1000disp(i);
end

在這里插入圖片描述

3.2 parfor循環(huán)進(jìn)度

用parfor并行去算一些東西的時候,有些需要循環(huán)很多次,我們是不清楚程序到底執(zhí)行了多少輪,如果可以看到進(jìn)度的話,時間太長了,我們或許就不會算了,

3.2.1 進(jìn)度條窗口方式

會用就行,可以直接拷貝走,這個是官方文檔里面找的

w = waitbar(0,'Please wait ...');% Create DataQueue and listener
D = parallel.pool.DataQueue;
afterEach(D,@parforWaitbar);N = 10000;
parforWaitbar(w,N)parfor i = 1:N% pause替換乘自己的就可以了pause(rand)send(D,[]);
end
delete(w);function parforWaitbar(waitbarHandle,iterations)persistent count h Nif nargin == 2% Initializecount = 0;h = waitbarHandle;N = iterations;else% Update the waitbar% Check whether the handle is a reference to a deleted objectif isvalid(h)count = count + 1;waitbar(count / N,h);endend
end

在這里插入圖片描述

3.2.2 底部進(jìn)度條方式

會用就行,也是官方網(wǎng)站里面找的,這個還需要一個文件,放到同一級目錄就可以了,代碼我放上邊鏈接了

% 設(shè)置循環(huán)次數(shù)
N = 10000;
% 創(chuàng)建一個迭代計數(shù)器對象
parfor_progress(N);
parfor i = 1:N% pause替換乘自己的就可以了pause(rand)parfor_progress;
end
parfor_progress(0);

在這里插入圖片描述

3.3 matlab互斥鎖

在parfor循環(huán)中,讀寫數(shù)據(jù)是很麻煩的,并行計算就是要計算結(jié)果的,但是parfor中的計算結(jié)果很難接收出來,量少的時候,還可以通過數(shù)組接收(2016版不可以),量多的時候,數(shù)組接收就不太現(xiàn)實(shí),每輪循環(huán)把數(shù)據(jù)寫入文件中呢,parfor會報錯,即使可以的話,由于matlab沒有互斥鎖,寫文件即使可以寫進(jìn)去,也會是亂的,沒辦法用

還是那句話,會用就行,替換成自己的就可以了,注釋寫里面了

% 創(chuàng)建一個 DataQueue 對象
dq = parallel.pool.DataQueue;
file = fopen('ccc.txt','w');% 多重匿名函數(shù)
fun_with_params = @(data) saveData(data, file);
% 在 DataQueue 上設(shè)置 afterEach 方法,
% 這個是給數(shù)據(jù)綁定一個處理方法,就是在信號發(fā)送以后,執(zhí)行那個處理方法,
% 這個處理方法不是并行的,同一時刻只有一個線程在處理數(shù)據(jù),其他的線程都要排隊
% 和互斥鎖的思想很像
afterEach(dq, fun_with_params);
% 在工作線程中定義處理函數(shù)并發(fā)送數(shù)據(jù)到 DataQueue
parfor i = 1:100% 替換成自己的a = rand();% 在這里通過 send 函數(shù)將數(shù)據(jù)發(fā)送到 DataQueue% 可以發(fā)送單個,也可也發(fā)送數(shù)組send(dq, a);
endfclose(file);function saveData(data, file)% 在此處編寫后處理代碼fprintf(file,'%.10f ', data); fprintf(file,'\n'); 
end

在這里插入圖片描述

3.4 parfor_progress.m

function percent = parfor_progress(N)
%PARFOR_PROGRESS Progress monitor (progress bar) that works with parfor.
%   PARFOR_PROGRESS works by creating a file called parfor_progress.txt in
%   your working directory, and then keeping track of the parfor loop's
%   progress within that file. This workaround is necessary because parfor
%   workers cannot communicate with one another so there is no simple way
%   to know which iterations have finished and which haven't.
%
%   PARFOR_PROGRESS(N) initializes the progress monitor for a set of N
%   upcoming calculations.
%
%   PARFOR_PROGRESS updates the progress inside your parfor loop and
%   displays an updated progress bar.
%
%   PARFOR_PROGRESS(0) deletes parfor_progress.txt and finalizes progress
%   bar.
%
%   To suppress output from any of these functions, just ask for a return
%   variable from the function calls, like PERCENT = PARFOR_PROGRESS which
%   returns the percentage of completion.
%
%   Example:
%
%      N = 100;
%      parfor_progress(N);
%      parfor i=1:N
%         pause(rand); % Replace with real code
%         parfor_progress;
%      end
%      parfor_progress(0);
%
%   See also PARFOR.% By Jeremy Scheff - jdscheff@gmail.com - http://www.jeremyscheff.com/error(nargchk(0, 1, nargin, 'struct'));if nargin < 1N = -1;
endpercent = 0;
w = 50; % Width of progress barif N > 0f = fopen('parfor_progress.txt', 'w');if f<0error('Do you have write permissions for %s?', pwd);endfprintf(f, '%d\n', N); % Save N at the top of progress.txtfclose(f);if nargout == 0disp(['  0%[>', repmat(' ', 1, w), ']']);end
elseif N == 0delete('parfor_progress.txt');percent = 100;if nargout == 0disp([repmat(char(8), 1, (w+9)), char(10), '100%[', repmat('=', 1, w+1), ']']);end
elseif ~exist('parfor_progress.txt', 'file')error('parfor_progress.txt not found. Run PARFOR_PROGRESS(N) before PARFOR_PROGRESS to initialize parfor_progress.txt.');endf = fopen('parfor_progress.txt', 'a');fprintf(f, '1\n');fclose(f);f = fopen('parfor_progress.txt', 'r');progress = fscanf(f, '%d');fclose(f);percent = (length(progress)-1)/progress(1)*100;if nargout == 0perc = sprintf('%3.0f%%', percent); % 4 characters wide, percentagedisp([repmat(char(8), 1, (w+9)), char(10), perc, '[', repmat('=', 1, round(percent*w/100)), '>', repmat(' ', 1, w - round(percent*w/100)), ']']);end
end

3.5 補(bǔ)充

按下面代碼執(zhí)行的,afterEach只能保證傳完數(shù)據(jù)以后執(zhí)行對應(yīng)函數(shù),并不代表一個循環(huán)里面的都一起執(zhí)行的
在這里插入圖片描述

% 創(chuàng)建一個 DataQueue 對象
dq1 = parallel.pool.DataQueue;
dq2 = parallel.pool.DataQueue;
file1 = fopen('ccc1.txt','w');
file2 = fopen('ccc2.txt','w');
% 多重匿名函數(shù)
fun_with_params1 = @(data) saveData(data, file1);
fun_with_params2 = @(data) saveData(data, file2);
% 在 DataQueue 上設(shè)置 afterEach 方法
afterEach(dq1, fun_with_params1);
afterEach(dq2, fun_with_params2);
% 在工作線程中定義處理函數(shù)并發(fā)送數(shù)據(jù)到 DataQueue
parfor i = 1:1000% 替換成自己的a = rand();% 在這里通過 send 函數(shù)將數(shù)據(jù)發(fā)送到 DataQueue% 可以發(fā)送單個,也可也發(fā)送數(shù)組send(dq1, a);send(dq2, a);
end% 等待所有數(shù)據(jù)接收完成% 顯示接收到的數(shù)據(jù)
% 輔助函數(shù)用于保存接收到的數(shù)據(jù)到數(shù)組
function saveData(data, file)% 在此處編寫后處理代碼fprintf(file,'%.10f ', data); fprintf(file,'\n'); 
end

改進(jìn)

% 創(chuàng)建一個 DataQueue 對象
dq1 = parallel.pool.DataQueue;
file1 = fopen('ccc11.txt','w');
file2 = fopen('ccc21.txt','w');
file3 = fopen('ccc31.txt','w');
% 多重匿名函數(shù)
fun_with_params1 = @(data1) saveData(data1, file1, file2,file3);
% 在 DataQueue 上設(shè)置 afterEach 方法
afterEach(dq1, fun_with_params1);
% 在工作線程中定義處理函數(shù)并發(fā)送數(shù)據(jù)到 DataQueue
parfor i = 1:100% 替換成自己的a = rand();data = {i,i,i}% 在這里通過 send 函數(shù)將數(shù)據(jù)發(fā)送到 DataQueue% 可以發(fā)送單個,也可也發(fā)送數(shù)組send(dq1, data);
end% 等待所有數(shù)據(jù)接收完成fclose(file1);
fclose(file2);
fclose(file3);
% 顯示接收到的數(shù)據(jù)
% 輔助函數(shù)用于保存接收到的數(shù)據(jù)到數(shù)組
function saveData(data, file1,file2,file3)% 在此處編寫后處理代碼data1 = data{1};data2 = data{2};data3 = data{1};fprintf(file1,'%.10f ',  data1); fprintf(file1,'\n'); fprintf(file2,'%.10f ',  data2);fprintf(file2,'\n'); fprintf(file3,'%.10f ',  data3);fprintf(file3,'\n'); 
end
http://m.risenshineclean.com/news/59511.html

相關(guān)文章:

  • wordpress關(guān)閉搜索功能搜索引擎優(yōu)化人員優(yōu)化
  • 怎樣注冊.com網(wǎng)站app用戶量排名
  • 網(wǎng)站開發(fā)軟件培訓(xùn)seo網(wǎng)絡(luò)培訓(xùn)班
  • b2b網(wǎng)站怎么發(fā)布信息微營銷
  • 東方網(wǎng)站建設(shè)百度打開百度搜索
  • 網(wǎng)站建設(shè)技術(shù)服務(wù)公司白度指數(shù)
  • wordpress還原站點(diǎn)設(shè)計網(wǎng)站用什么軟件
  • 深圳做手機(jī)網(wǎng)站建設(shè)seo優(yōu)化包括什么
  • 什么店是做網(wǎng)站制作的今天最火的新聞頭條
  • 紹興免費(fèi)做網(wǎng)站專業(yè)搜索引擎seo服務(wù)
  • 廣告體驗程序網(wǎng)站開發(fā)快速排名方案
  • 建設(shè)網(wǎng)站各方面費(fèi)用預(yù)算網(wǎng)絡(luò)宣傳
  • 購物網(wǎng)站建設(shè)比較好的知乎關(guān)鍵詞排名優(yōu)化工具
  • 網(wǎng)站后臺怎么修改前臺的某個超鏈接網(wǎng)址常州seo招聘
  • 勝芳網(wǎng)站建設(shè)qiansi湖南靠譜的關(guān)鍵詞優(yōu)化
  • 做網(wǎng)站比特幣錢包淘寶關(guān)鍵詞優(yōu)化推廣排名
  • 嘉興市建設(shè)委員會網(wǎng)站seo實(shí)戰(zhàn)視頻
  • 黃浦網(wǎng)站制作seo國外推廣軟件
  • 做照片的網(wǎng)站有哪些seo網(wǎng)站關(guān)鍵詞排名優(yōu)化
  • 國外黑客網(wǎng)站成都多享網(wǎng)站建設(shè)公司
  • 做網(wǎng)站 幫別人賣服務(wù)器地推拉新接單網(wǎng)
  • 開發(fā)網(wǎng)站比較好的公司廈門人才網(wǎng)597人才網(wǎng)
  • 響應(yīng)式網(wǎng)站建設(shè)報價單百度信息流投放在哪些平臺
  • 設(shè)計網(wǎng)站的三個要素揭陽seo推廣公司
  • 尚云網(wǎng)站建設(shè)網(wǎng)絡(luò)運(yùn)營怎么學(xué)
  • favicon wordpress做seo需要用到什么軟件
  • 怎么做公司網(wǎng)站需要什么科目百度問答官網(wǎng)
  • 網(wǎng)購手表網(wǎng)站查詢網(wǎng)站域名
  • 武漢網(wǎng)絡(luò)推廣公司哪家服務(wù)好長沙seo男團(tuán)
  • 優(yōu)化網(wǎng)絡(luò)的軟件下載seo百度關(guān)鍵詞優(yōu)化