I have two questions, which I think that are related enough to be part of a single question. But in case they are not, I can ask the them as separate questions. Please let me know. I also apologize in advance because I have the impression that I am doing something very wrong, but I don't know what it is.
So far, I run the following code in Python (using Jupyter notebooks, if it makes a difference):
First, I initialize a very long (multilevel?) list:
object = [[[[[[[[None for i in range(2)]
for j in range(2)]
for k in range(2)]
for l in range (2)]
for m in range (2)]
for n in range (2)]
for o in range (2)]
for p in range (2)]
Next, I run a bunch of loops, one inside the other, and run a single function (that depends on all the indices that I am using in the loop), assigning the result to one of the positions that I created above:
for i in range(2):
for j in range(2):
for k in range(2):
for l in range(2):
for m in range(2):
for n in range(2):
for o in range(2):
for p in range(2):
object[i][j][k][l][m][n][o][p] = function(i,j,k,l,m,n,o,p)
Here are the two related questions:
The objects that the function returns in each iteration are completely independent from each other (I could run each iteration of the loop in one computer and collect them later, for example). So I imagine that this loop would be the ideal candidate to be solved in parallel/multiprocessing. If so, how do I do that? I found a few mentions of running nested loops in parallel, but I could not understand how it applies for my case. Full disclosure: I never ran anything in parallel in Python.
Is this list (referencing to this rather unpleasant
object[i][j][k][l][m][n][o][p]
) how you would properly keep the results (in a way that you can find later)? Or could you maybe suggest a better way? If it is relevant, the objects returned by the function have properties such as pandas dataframes, numbers, and strings.