Question: Threaded-Matrix

Question:Threaded-Matrix

mysm 32 Maple

I changed my code to multi-threaded type. but my run time increased! and my CPU usage became 65-70%.I think I made a mistake in programming.
but i have a different question too. I read a paper that said: "when you use a matrix or array instead of single integer in maple, your run time will be badly increase, because your total CPU usage will decrease! i't a result of delay in writing matrix element in ram and as CPU has no command to process and is waiting for data from RAM"
i want to know if it is correct or not.
because of it i attached two simple codes for you to test the problem.(save as .mws and run in classic worksheet)

you can use matrix too.

 

1st code
--------------------------------------------------------------
restart;
with(Threads);
Post1:=proc()
M:=0;
for i from 1 to 300000000  do
M:=M+1:
end do:  end proc;

Post2:=proc()
L:=0;
for j from 1 to 300000000  do
L:=L+1:
end do:  end proc;
Threads:-Wait( Threads:-Create( Post1(  ) ),Threads:-Create( Post2(  ) ) );
--------------------------------------------------------------
2nd code
--------------------------------------------------------------
restart;
with(Threads);
Post1:=proc()
M[1]:=0;
for i from 2 to 300000000  do
M[i]:=M[i-1]+1:
end do:  end proc;

Post2:=proc()
L[1]:=0;
for j from 2 to 300000000  do
L[i]:=L[i-1]+1:
end do:  end proc;
Threads:-Wait( Threads:-Create( Post1(  ) ),Threads:-Create( Post2(  ) ) );

Please Wait...