"""
Copyright (C) 2012 ANSYS, Inc. and its subsidiaries.  All Rights Reserved.

$LastChangedDate: $
$LastChangedRevision: $
$LastChangedBy: $
"""

NUM_THREADS_ENVIRONMENT_VARIABLE_NAME = 'OMP_NUM_THREADS'

def registerTransformationEntries():
    return [('Environment', { 'SolverTag': 'Polyflow' }, removeNumThreadsEnvironmentVariable),
            (('Arguments', ['NumberOfProcesses']), { 'SolverTag': 'Polyflow', 'ExecutionMode': 'Parallel' }, appendParallelArgument)]

def appendParallelArgument(arguments, inputDataDict):
    return arguments.strip() + ' -th ' + str(inputDataDict['NumberOfProcesses'])

def removeNumThreadsEnvironmentVariable(environment):
    if NUM_THREADS_ENVIRONMENT_VARIABLE_NAME in environment:
        del environment[NUM_THREADS_ENVIRONMENT_VARIABLE_NAME]
    return environment
    
def fixNumberOfProcessesOnClusters(numberOfProcesses, inputDataDict):
    # Note by Mike (8/2/2012) - At the moment, the only purpose of this is to fix NumberOfProcesses for the validation code.
    # The Polyflow Addin currently adds the correct number of processes to the command line.
    return inputDataDict['MachineList'][0][1]
    
def stripMachineListDownToMasterNodeOnly(machineList):
    if machineList == None or len(machineList) == 0:
        return machineList
    return machineList[:1]