import os def fun(x,y): # here compute something with the parameters x and y print(f'Calculation with {x} and {y}...') def get_params(X,Y): # Make a list of all possible combinations # This can be done in a one-liner: # params = [(a,b) for a in X for b in Y] # but if you don't like that here's a regular double loop # which is easier to extend to parameter sweeps with 3,4,5 etc # parameters. params = [] for a in X: for b in Y: params.append( (a,b) ) # Get the SGE_TASK_ID from the job array # Subtract 1 for Python 0-based indexing task_id = int(os.environ['SGE_TASK_ID']) - 1 return params[task_id] if __name__ == '__main__': # List all values for the two parameters X = range(1,5) # numbers 1-4 Y = ('A','B','C') # string values # Call the calculation function with the # selected parameters. fun(*get_params(X,Y)) # or if you prefer: # x,y = get_params(X,Y) # fun(x,y) # An alternative: # Write a separate Python script to generate all of the possible parameter # combos and write them to a file. Then in this script read in that # file and use SGE_TASK_ID to select the correct parameters from the # matching row in the file.