Navigation: Scripting Reference Manual > Functions & Subroutines > IPCGetLoadBalance

 

IPCGetLoadBalance

 

Contact Us: fredsupport@photonengr.com

 

Description

This function retrieves the currently assigned work unit load balancing mode.  It can be called from master scripts and remote scripts.

 

 

Syntax

lbMode = IPCGetLoadBalance( lbString )

 

 

Parameters

lbMode (Long)

Returned value indicating the load balancing mode.  Return values are:

1 = "static"

2 = "dynamic"

 

 

lbString As String

Passed in as an argument.  After function execution this variable indicates the load balancing mode in string form.  Result will be "static" or "dynamic".

 

 

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

T_IPCINSTANCE

 

 

 

 

 

Copyright © Photon Engineering, LLC