tutorials:grolink-on-kubernetes
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:grolink-on-kubernetes [2024/12/02 15:36] – tim | tutorials:grolink-on-kubernetes [2024/12/02 15:38] (current) – [Generate input data with SALib] tim | ||
---|---|---|---|
Line 270: | Line 270: | ||
</ | </ | ||
- | '' | + | '' |
Line 349: | Line 349: | ||
</ | </ | ||
+ | For simplicity you can find the last python code here in one file: | ||
+ | <code python> | ||
+ | import numpy as np | ||
+ | from SALib.sample import saltelli | ||
+ | from GroPy import GroPy | ||
+ | import multiprocessing | ||
+ | import kr8s | ||
+ | from kr8s.objects import Pod | ||
+ | WORKERCOUNT =9 | ||
+ | |||
+ | # defining the problem | ||
+ | problem = { | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | } | ||
+ | param_values = saltelli.sample(problem, | ||
+ | |||
+ | #creating a link for each pod | ||
+ | links=[] | ||
+ | selector = {' | ||
+ | for podS in kr8s.get(" | ||
+ | print(" | ||
+ | links.append(GroPy.GroLink(" | ||
+ | |||
+ | # create an queue to assign pods to workers | ||
+ | pods = multiprocessing.Queue() | ||
+ | n = len(links) | ||
+ | for i in range(0, | ||
+ | pods.put(links[i%n]) | ||
+ | |||
+ | #initialize each worker | ||
+ | def init_worker(function, | ||
+ | function.cursor = pods.get().openWB(content=open(" | ||
+ | |||
+ | # the actual execution | ||
+ | def grow(val): | ||
+ | lenV, angle = val | ||
+ | results = [] | ||
+ | #overwrite the parameters in the file | ||
+ | grow.cursor.updateFile(" | ||
+ | static float lenV=""" | ||
+ | static float angle=""" | ||
+ | """,' | ||
+ | grow.cursor.compile().run() | ||
+ | for x in range(0, | ||
+ | data=grow.cursor.runRGGFunction(" | ||
+ | results.append(float(data[' | ||
+ | return results | ||
+ | | ||
+ | # Multi processing | ||
+ | pool = multiprocessing.Pool(processes=WORKERCOUNT, | ||
+ | results = pool.map(grow, | ||
+ | pool.close() | ||
+ | y = np.array(results) | ||
+ | |||
+ | # save result | ||
+ | np.savetxt(" | ||
+ | |||
+ | </ |
tutorials/grolink-on-kubernetes.1733150215.txt.gz · Last modified: 2024/12/02 15:36 by tim