At the moment two instructions can result in parallel code. First is for in instruction used to call procedure.
for e in mainList parallel test(e)
At the beginning procedure test is called for first list element and processed on first processor core, second list element is processed on next core and so on to last available core. Now program waits all cores to finish their tasks and everything starts again.
class A text="" parsed=[str] list prepareA(int itemCount)= mainList=[A] for i=1 to itemCount ala=new A ala.text=toStr(i)+" Alice in wonderland" append(mainList,ala) return mainList proc test(A ala)= printNL(ala.text) ala.parsed=split(ala.text) initMT() # at the beginning multicore support must be started mainList=[A] mainList=prepareA(10) for e in mainList parallel #!!!!!!!!!!!!!!!! test(e)
Second instruction resulting in parallel code is for instruction where subinstructions are called parallely.
for k=0 to 9 parallel printNL(k) test1(arr,k)
When two cores are available code:
for k=0 to 4 printNL(k) test1(arr,k)
will be processed on first core and code:
for k=5 to 9 printNL(k) test1(arr,k)
wil be processed on another core.
proc test1(int [10] arr,int k)
x=k+2
set(arr,k,x) # arr[k]=x
initMT()
int [10] arr
for k=0 to 9 parallel #!!!!!!!!!!!!!!!!!!!!
printNL(k)
test1(arr,k)
printNL("after :")
for k=0 to 9
s=toStr(k)+","+toStr(arr[k])
printNL(s)
To use parallel instructions option multithreading must be set and a0.ala will be compiled to a0_mt.exe.