Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Parameter

Type

Prompt

Value

pLogOutput

String

Record in process log

1

pMaxThreads

String

Optional: Maximum number of threads for parallel processing: default =1

1

pDimPar

String

Optional: Parallelization dimension: default =blank (FIN Company)

pThreadID

String

Private: Thread ID (don't override, leave 0 as default)

0

Prolog (declarationsbefore Initialize Logging region):

Code Block
cDimPar pLogOutput = TRIM( pLogOutput );
nLogOutput = StringToNumber( If( pLogOutput @= 'FIN', Company';
'0', pLogOutput ));

Prolog (after declarationstrimming parameter values):

Code Block
nMaxThreads = StringToNumber( If( pMaxThreads @= '', '0', pMaxThreads ));
nThreadID = StringToNumber( If( pThreadID @= '', '0', pThreadID ));

Prolog (declarations):

Code Block
cCubParam = '}APQ Settings';
cDimPar = 'FIN Company';
cCubThreadCtrl = '}APQ C3 Thread Control';

cDimensionDelim = CellGetS( cCubParam, 'pDimDelim', 'String' );
cElementStartDelim = CellGetS( cCubParam, 'pEleStartDelim', 'String' );
cElementDelim = CellGetS( cCubParam, 'pEleDelim', 'String' );

cLogRecordThresholdRec = CellGetN( cCubParam, 'Progress logging threshold - number of records', 'Numeric' );
cLogRecordThresholdSec = CellGetN( cCubParam, 'Progress logging threshold - time', 'Numeric' );
cThreadPollingInterval = CellGetN( cCubParam, 'Thread polling interval (seconds)', 'Numeric' );
cMaxRunTime = CellGetN( cCubParam, 'Maximum run time allowed for parallel processing (seconds)', 'Numeric' );
cMaxInitTime = CellGetN( cCubParam, 'Maximum process initialization time allowed for parallel processing (seconds)', 'Numeric' );
cThreadMonitoringEnabled = 1;
If( cMaxRunTime <= 0 % cMaxRunTime > 0 & nMaxThreads = 1 );
  cMaxRunTime = 0;
  cThreadMonitoringEnabled = 0;
EndIf;
sMaxRunTime = NumberToString( cMaxRunTime );

Prolog (parameter testing region):

...

Code Block
If ( nMaxThreads > 1 & nThreadID >= 0 );
  # Parallel processing
  nThreads = nMaxThreads;
  If ( nThreadID = 0 );
    # This is master - spawn worker threads. Master will be also processing data.
    sThreads = NumberToString( nThreads );
    sMessage = Expand( 'Data processing will run on %sThreads% thread' | If( nThreads > 1, 's', '') | '.' );
    sSequenceID = NumberToString( nMultiMsgJSON );
    sMessageJSON = INSRT(' "message":"', sMessage | '"', 1);
    sMultiMsg = Expand( '%sMultiMsg%' | If(LONG(sMultiMsg)=0, '', ', ') | '"' | NumberToString( nMultiMsgJSON ) | '":{%sMessageJSON%}' ); nMultiMsgJSON = nMultiMsgJSON + 1; 
    LogOutput( 'Info', sMessage );
    
    sFilter = '}Clients' | cElementStartDelim | cUserName;
    sFilter = sFilter | cDimensionDelim | '}Processes' | cElementStartDelim | cThisProcName;
    
    sProc = '}bedrock.cube.view.create';
    nRet = ExecuteProcess( 	sProc,
      'pLogOutput', nLogOutput,
    	'pCube', cCubThreadCtrl,
    	'pView', cViewClr, 
    	'pFilter', sFilter,
    	'pSuppressConsol', 1,
    	'pSuppressRules', 0,
    	'pDimDelim', cDimensionDelim,
    	'pEleStartDelim', cElementStartDelim,
    	'pEleDelim', cElementDelim,
    	'pTemp', 1
    );
    
    IF( nRet <> ProcessExitNormal );
      nErrors = nErrors + 1;
      sRet = NumberToString( nRet );
      sMessage = Expand( 'Call to %sProc% has finished with errors (code = %sRet%).' );
      sSequenceID = NumberToString( nMultiMsgJSON );
      sMessageJSON = INSRT(' "message":"', sMessage | '"', 1);
      sMultiMsg = Expand( '%sMultiMsg%' | If(LONG(sMultiMsg)=0, '', ', ') | '"' | NumberToString( nMultiMsgJSON ) | '":{%sMessageJSON%}' ); nMultiMsgJSON = nMultiMsgJSON + 1; 
      LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
      ProcessBreak;
    EndIF;

    ViewZeroOut( cCubThreadCtrl, cViewClr );
    
    CellPutN( 1, cCubThreadCtrl, cUserName, cThisProcName, pThreadID, 'scheduled' );
    CellPutN( 1, cCubThreadCtrl, cUserName, cThisProcName, pThreadID, 'running' );
    CellPutN( 0, cCubThreadCtrl, cUserName, cThisProcName, pThreadID, 'completed' );
    nThread = 1;
    While ( nThread < nThreads );
      sThreadID = NumberToString( nThread );
      CellPutN( 1, cCubThreadCtrl, cUserName, cThisProcName, sThreadID, 'scheduled' );
      nThread = nThread + 1;
    End;
    CubeSaveData( cCubThreadCtrl );
    nThread = 1;
    While ( nThread < nThreads );
      sThreadID = NumberToString( nThread );
      RunProcess( cThisProcName,
        'pLogOutput', pLogOutput,# TODO: Add proper parameters - all are passed through
         'pVersion'RunProcess( cThisProcName,
pVersion,
        'pYearpLogOutput', pYear,
        'pCompany', pCompany,
        'pBSEG1', pBSEG1,
        'pBSEG2', pBSEG2,
        'pBSEG3', pBSEG3,
        'pBSEG4', pBSEG4,pLogOutput,
         'pThreadID', sThreadID,
        'pDimPar', pDimPar,
        'pMonthFrom', pMonthFrom,
        'pMonthTo', pMonthTo,
        'pMaxThreads', pMaxThreads,
        'pReattachRule', '0'
      );
      nThread = nThread + 1;
    End;
  Else;
    CellPutN( 1, cCubThreadCtrl, cUserName, cThisProcName, pThreadID, 'running' );
    CellPutN( 0, cCubThreadCtrl, cUserName, cThisProcName, pThreadID, 'completed' );
  EndIf;
EndIf;

...