BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

Or do I have to use the 'nthreads' option?

My code runs successfully but it takes a long time to execute. 

 


options casdatalimit=all;
proc cas;
   loadactionset 'iml';    /* load the iml action set (only once per session) */
run;

source imly;
KeepStmt1 = 'KEEP=codidoc codopera  ';
KeepStmt2 = 'KEEP=_numeric_  ';
KeepStmt3 = 'KEEP=QNUMMESE  ';
x = matrixCreateFromCAS('PUBLIC', 'exp2', KeepStmt2 );
y=matrixCreateFromCAS('PUBLIC', 'EXP2', KeepStmt1);
QNUMMESE = matrixCreateFromCAS('PUBLIC', 'EXP2', KeepStmt3);

varnames={&var2s.};

X=X||J(NROW(X),1,0);
XT=(SHAPE(DIF(X), NROW(X)) [, 2:NCOL(X)])#2;
idx=loc((x[, 2:NCOL(X)]+xt)=1);
xt[idx]=1;

y=y[,2]||y[,1];

t2=unique(qnummese);
/* rowhead=char(t2); */

t22=(repeat(t2, nrow(x))=qnummese)`*(xt = 2);

t22_sum=t22 [+];
ctr=(xt = 2) [+]; 

idx1=loc(t22 <> 0);
s = ndx2sub(dimension(t22), idx1);

/* PRINT QNUMMESE y XT T2 T22 T22_SUM CTR IDX1 S; */



res0=j(nrow(s), ncol(x)-1, .);
res0_perc=res0;

do i=1 to ncol(idx1);
idx2=loc( ( (qnummese=t2[s[i,1]])# (xt[, s[i,2]]=2) )=1);
/* PRINT IDX2; */
res0[i,s[i,2]] = t22[idx1[i]];
/* PRINT RES0; */
res0[i,(s[i,2]+1):ncol(xt)]=(x [loc(element(y[,1], y[idx2,1])),(s[i,2]+1):ncol(x)-1] <>0) [+,];
/* PRINT RES0; */
res0_perc[i,(s[i,2]):ncol(xt)]=res0[i,(s[i,2]):ncol(xt)]/res0[i,s[i,2]];
end;

/* endsource; */
/* iml / code=imly; */
/* run; */


rown=catx("|", t2 [s[,1]], varnames[s[,2]]);

call MatrixWriteToCAS(res0, '', '_crm_fun', varnames);
call MatrixWriteToCAS(res0_perc, '', '_crm_fun_perc', varnames);
call MatrixWriteToCAS(rown, '', '_crm_fun_id');
    
endsource;
iml / code=imly;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

> Does an IML action run automatically on several nodes?

No, it doesn't. Your session determines how many nodes are available, but the program only uses multiple nodes for distributed functions. Examples of a distributed function are MapReduce, ParTasks, and reading/writing CAS tables. See https://go.documentation.sas.com/doc/en/pgmsascdc/v_026/casactiml/casactiml_iml_details08.htm

 

> Or do I have to use the 'nthreads' option?

The NTHREADS= option determines how many threads are available on each node. But only multithreaded operations use the threads. Multithreaded operations include the distributed functions (as above) and linear algebra operations such as SOLVE and SVD. See https://go.documentation.sas.com/doc/en/pgmsascdc/v_029/casimllang/casimllang_common_sect015.htm#cas... 

 

With the exception of the read/write operations, your program will run in a single thread on the controller node. 

 

I cannot determine what your program is supposed to do, but if you explain it a little and include some example data, we might be able to offer a way to improve its efficiency.

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

> Does an IML action run automatically on several nodes?

No, it doesn't. Your session determines how many nodes are available, but the program only uses multiple nodes for distributed functions. Examples of a distributed function are MapReduce, ParTasks, and reading/writing CAS tables. See https://go.documentation.sas.com/doc/en/pgmsascdc/v_026/casactiml/casactiml_iml_details08.htm

 

> Or do I have to use the 'nthreads' option?

The NTHREADS= option determines how many threads are available on each node. But only multithreaded operations use the threads. Multithreaded operations include the distributed functions (as above) and linear algebra operations such as SOLVE and SVD. See https://go.documentation.sas.com/doc/en/pgmsascdc/v_029/casimllang/casimllang_common_sect015.htm#cas... 

 

With the exception of the read/write operations, your program will run in a single thread on the controller node. 

 

I cannot determine what your program is supposed to do, but if you explain it a little and include some example data, we might be able to offer a way to improve its efficiency.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 383 views
  • 1 like
  • 2 in conversation