Description This function is used in a remote script to retrieve the work units assigned to the remote by the master. The action taken for a given work unit is programmed by the user in the remote script. The use of this command in a remote script is only required when the remote script is intended to leverage the work units concept.
The exact work unit values assigned to any particular remote node will depend on the distributed computing load balancing mode, which may be "static" or "dynamic". See the IPCSetLoadBalance script command for more information about the load balancing modes available in FRED.
For the purposes of the discussion below, the following terms are used: WorkUnitTotal = The total number of work units assigned across all remote instances WorkUnit = The starting work unit number currently assigned to the remote WorkUnitCount = The number of work units assigned to the remote
If the load balancing mode is "static": Work units will be assigned to all active remotes in approximate proportion to their relative speeds as specified in the connection configuration file (or connections() array). The first call to IPCGetWorkUnits in the remote script will return the work unit information assigned by the master. The user should call IPCGetWorkUnits only once when in "static" load balancing mode. In this case, subsequent calls of IPCGetWorkUnits in the remote script will return values of zero for both WorkUnitCount and WorkUnitTotal (with the value of WorkUnit unchanged) as a signal that no more work units will be assigned to the remote. The user should program the script to exit after processing all assigned work units.
If the load balancing mode is "dynamic": The master will initially assign one work unit to each active remote node and the first call to IPCGetWorkUnits by a remote will return the currently assigned work unit information. The script should not call IPCGetWorkUnits again until after the calculation using the currently assigned work unit has completed. At that point, subsequent calls to IPCGetWorkUnits will return work unit information indicating one of three possible states: 1) the value of WorkUnitTotal is zero, in which case the distributed computation job is finished, the Work Units have been exhausted, and the script should exit 2) the value of WorkUnitCount is zero but WorkUnitTotal is not zero, in which case the job is not finished but the master has not yet assigned a new work unit specification to the remote, so the script should attempt to get a new work unit assignment by calling the IPCGetWorkUnits command again 3) the values of both WorkUnitCount and WorkUnitTotal are not zero, in which case the script should perform the calculation using the current work unit and then call IPCGetWorkUnits again.
The following code snippet shows how to structure calls to IPCGetWorkUnits that will properly handle both the "static" and "dynamic" load balancing cases:
Dim WorkUnit As Long, WorkUnitCount As Long, WorkUnitTotal As Long, curWu As Long Do WorkUnitTotal = IPCGetWorkUnits( WorkUnit, WorkUnitCount) If (WorkUnitCount>0) And (WorkUnitTotal >0) Then For curWu = WorkUnit To (WorkUnit+WorkUnitCount-1) 'Insert code here that uses curWu to make model changes, perform calculation, etc. Next End If Loop While (WorkUnitTotal >0)
Syntax wuTotal = IPCGetWorkUnits( wu, wuCount )
Parameters wuTotal (Long) Returned total number of work units assigned across ALL remote instances.
wu As Long Passed in as an argument. After the function executes, this indicates the starting work unit number currently assigned to the remote.
wuCount As Long Passed in as an argument. After the function executes, this indicates the number of work units currently assigned to the remote.
Example The example below is a script designed to be run on a remote instance that can be used with static or dynamic load balancing. The context is a thermal self emission analysis, where a source is raster scanned across each pixel of a 2D array and reverse raytraced in order to build up a thermal irradiance map. Some of the auxiliary functions required for the script below are not included here; the user should refer to the sample files for a full implementation of this example.
Sub Main
'This script is an implementation of the thermal self emission calculation where a source 'is raster scanned across a detector and a reverse raytrace is performed at each pixel. From 'this series of reverse raytraces, the 2D thermal image distribution is built up in an array. 'This particular implementation has been written in such a way to leverage static or dynamic 'load balancing for a distributed computing calculation.
'Constant and wavelength range. Dim sbConst As Double, wl1 As Double, wl2 As Double sbConst = 5.670323*10^-14 'W/mm^2/K^4 wl1 = 8 wl2 = 12
'Analysis surface and source node Dim anaNode As Long, srcNode As Long anaNode = FindFullName( "Analysis Surface(s).detectorAna" ) srcNode = FindFullName( "Optical Sources.detectorEmitter" )
'Retrieve surface contributions Dim surfList() As Long, tempList(), emissList() GetContributingSurfaces( surfList(), tempList(), emissList(), False )
'Create an empty ARN grid by calling an irradiance distribution 'immediately without any rays in the system. We will fill in the 'values of the data array inside of the work loop. Dim arnOut As Long, data() As Double IrradianceToARN( anaNode, "Thermal Irradiance", arnOut ) ARNGetDataAsDoubleArray( arnOut, data() ) ARNSetLocked( arnOut, True )
'May be useful to print information to a "debug" text file for tracking Open "Debug.fdcd" For Output As #1
'Print the load balancing mode to the debug file Dim lbS As String IPCGetLoadBalance( lbS ) Print #1, "Load balance mode = " & lbS
'Print a header line to the debug file Print #1, "WuTot" & "," & "Wu" & "," & "WuCount"
'This is our work unit processing loop Dim xPos As Double, yPos As Double, pwr As Double Dim col As Long, row As Long, curEnt As Long Dim wuTotal As Long, wu As Long, wuCount As Long, curWu As Long 'This is a generic loop that will work regardless of whether the load 'balancing was set to static or dynamic in the master script Do wuTotal = IPCGetWorkUnits( wu, wuCount )
If (wuCount > 0) And (wuTotal > 0) Then
'Log info in our debug text file Print #1, wuTotal & "," & wu & "," & wuCount
For curWu = wu To (wu+wuCount-1) 'Move the source into position for the current work unit CalcSourceXY( curWu, anaNode, srcNode, xPos, yPos, col, row ) Update
'Log info in our debug text file Print #1, "Beginning work unit " & curWu Print #1, Chr(9) & "xPos=" & xPos Print #1, Chr(9) & "yPos=" & yPos Print #1, Chr(9) & "col=" & col Print #1, Chr(9) & "row=" & row
'Trace the source TraceCreate()
'Get thermal contributions pwr = 0.0 For curEnt = 0 To UBound( tempList ) If tempList(curEnt)>0 Then pwr += emissList( curEnt )*BlackBodyFractionalEnergy( wl1, wl2, tempList( curEnt ) )*sbConst*(tempList( curEnt )^4)*GetSurfIncidentPower( surfList( curEnt ) ) End If Next
'Assign value to data array data(col,row) = pwr Next curWu
End If Loop While (wuTotal>0)
'Close the debug file Close #1
'Save the data array back into the ARN ARNSetDataAsDoubleArray( arnOut, data() )
'Save the ARN to file ARNWriteToFile( arnOut, "ThermalIrradiance.fgd", True, True )
End Sub
See Also Distributed Computing Script Commands
|