2017-03-12 27 views
0

可能有一個簡單的解決方案,但目前我無法解決它。也許有人可以幫助我。SAS並行處理:隨後啓動k個並行作業,直到完成N個作業

所以,我有以下問題:

我有,我想完成總N SAS工作。由於我的機器資源太有限,無法同時啓動所有N作業,我只想同時開始說k = 5。每次完成一項工作時,我想開始下一項工作。工作完成的順序並不重要。

目前,我讓所有的k=5作業結束之前,我開始在未來5 因此,這裏是僞代碼,我目前在做什麼:

/*The following macro starts k threads*/ 
%macro parallel_processing(k); 

options fullstimer autosignon=yes sascmd="sas -nonews -threads"; 

%global thread jj idlist; 

/*These are the N ID numbers for the jobs*/ 
%let idlist = 1 2 3 4 5 ... N; 
%let jj = 0; 
%do %until(&jj.=N); 
    %do thread = 1 %to &k.; 
     %let jj = %eval(&thread.+&jj.); 
     %syslput thread = &thread; 
     %syslput jj = &jj.; 
     %syslput idlist = &idlist.; 

     rsubmit process=task&thread. wait=no sysrputsync=yes; 

      %let id =%scan(%trim(&idlist.),&jj.); 
      /*Do the job*/ 
      %job(id); 

     endrsubmit; 
    %end; 

    /* HERE IS MY PROBLEM: 
     I want to wait for each job separately, and start a new one 
     with an increased id. So that constantly k threads are busy. 
    */ 

    /* Wait for all threads to finish */ 
    waitfor _all_ %do thread = 1 %to &k.; 
     task&thread 
    %end; 

    /* GET RESULTS FROM THREADS */ 
    %do thread = 1 %to (&k.); 
     rget task&thread; 
    %end; 

    /* SIGNOFF THREADS*/ 
    %do thread = 1 %to (&k.); 
     signoff task&thread; 
    %end; 
%end; 
%mend parallel_processing; 

%parallel_processing(k); 

也許有人有一個很好的想法,我會心懷感激!先謝謝你。

回答

2

使用waitfor _any_ ...而不是waitfor _all_ ...

  1. 啓動第5個任務,保持一個音符,其中5項任務是積極的。
  2. 等待他們中的任何一個完成並從活動任務列表中刪除它。
  3. 從隊列中啓動下一個任務,並將其添加到活動任務列表中。
  4. 重複步驟2和3,直到隊列中沒有剩餘任務。

您可以使用任何您喜歡的方法來跟蹤哪5個任務當前處於活動狀態。

+0

謝謝你的回答。問題是如何跟蹤哪5個任務正在運行? 'LISTTASK'將結果打印到日誌文件中,我如何訪問當前正在運行的任務列表? –

+1

使用您在RSUBMIT語句中使用CMACVAR =選項定義的宏變量來檢查狀態。 – Tom

+0

感謝您的提示!很好的作品:D –