Re: ParallelTable doesn't work, but Table does
- To: mathgroup at smc.vnet.net
- Subject: [mg101774] Re: [mg101689] ParallelTable doesn't work, but Table does
- From: Iván Lazaro <gaminster at gmail.com>
- Date: Thu, 16 Jul 2009 08:22:19 -0400 (EDT)
- References: <200907140937.FAA01989@smc.vnet.net> <4A5CD404.4040301@mit.edu>
Sorry for the inconvenience; the code below work as is expected with Table. Num = 4; Time = 600; cont = 0; r[r2_, r3_, r4_] := {1, r2, r3, r4}; A[a12_, a13_, a14_, a21_, a23_, a24_, a31_, a32_, a34_, a41_, a42_, a43_] := {{1, a12, a13, a14}, {a21, 1, a23, a24}, {a31, a32, 1, a34}, {a41, a42, a43, 1}}; Variable[] := Flatten[Table[Subscript[x, i][t], {i, 1, Num}]] JacobianMatrix[funs_List, vars_List] := Outer[D, funs, vars] CondIni[] := Table[{Subscript[x, i][0] == 0.1*i}, {i, 1, Num}] Y = Table[{Subscript[x, i][t], Subscript[x, i + 4][t], Subscript[x, i + 8][t], Subscript[x, i + 12][t]}, {i, 5, 8}]; YI9 = Flatten[ Table[{Subscript[x, i][0] == If[Mod[i, 5] == 0, 1, 0, 0], Subscript[x, i + 4][0] == If[Mod[i + 4, 5] == 0, 1, 0, 0], Subscript[x, i + 8][0] == If[Mod[i + 8, 5] == 0, 1, 0, 0], Subscript[x, i + 12][0] == If[Mod[i + 12, 5] == 0, 1, 0, 0]}, = {i, 5, 8}]]; YI3 = Flatten[CondIni[]]; Ecua[r2_, r3_, r4_, a12_, a13_, a14_, a21_, a23_, a24_, a31_, a32_, a34_, a41_, a42_, a43_] := Flatten[Table[ r[r2, r3, r4][[i]]* Subscript[x, i][ t]*(1 - Sum[ A[a12, a13, a14, a21, a23, a24, a31, a32, a34, a41, a42, a43][[i, j]]*Subscript[x, j][t], {j, 1, Num}]), {i, 1, Num}]]; Table[J = JacobianMatrix[ Ecua[r2, r3, r4, a12, a13, a14, a21, a23, a24, a31, a32, a34, a41, a42, a43], Variable[]]; E1 = Flatten[Transpose[J.Y]]; EQ3 = Table[ D[Subscript[x, i][t], {t, 1}] == Ecua[r2, r3, r4, a12, a13, a14, a21, a23, a24, a31, a32, a34, a41, a42, a43][[i]], {i, 1, 4}]; EQ9 = Table[D[Subscript[x, i][t], {t, 1}] == E1[[i - 4]], {i, 5, 20}= ]; sol = NDSolve[Join[EQ9, EQ3, YI3, YI9], Table[Subscript[x, i][t], {i, 1, 20}], {t, 0, Time}, MaxSteps -> Infinity, AccuracyGoal -> 2]; u = Table[Random[], {4}]; PhiT = Transpose[ Table[{Subscript[x, i][t], Subscript[x, i + 4][t], Subscript[x, i + 8][t], Subscript[x, i + 12][t]}, {i, 5, 8}] /. sol /. t -> Time]; ExpLyap = Log[Norm[PhiT.u]]/Time; If[ExpLyap > 0, PutAppend[ Join[A[a12, a13, a14, a21, a23, a24, a31, a32, a34, a41, a42, a43], r[r2, r3, r4], ExpLyap], "File"]], {a12, 0.01, 0.01, 0.01}, {a13, 0.01, 0.01, 0.01}, {a14, 0.01, 0.01, 0.01}, {a21, 0.01, 0.01, 0.01}, {a23, 0.01, 0.01, 0.01}, {a24, 0.01, 0.01, 0.01}, {a31, 0.01, 0.01, 0.01}, {a32, 0.01, 0.01, 0.01}, {a34, 0.01, 0.01, 0.01}, {a41, 0.01, 0.01, 0.01}, {a42, 0.01, 0.01, 0.01}, {a43, 0.01, 0.01, 0.01}, {r2, 0.01, 0.01, 0.01}, {r3, 0.01, 0.01, 0.01}, {r4, 1.11, 1.21, 0.01}] 2009/7/15 Zach Bj=F8rnson <bjornson at mit.edu> > Hi- > > I'm a bit confused by this code. There's a syntax error (the final ] on t= he > last line doesn't have a matching bracket, nor do those iterators a21...r= 4 > apply to anything as the code is written) somewhere, but I can't tell whe= re. > I also can't quite tell what the replacement is for the ParallelTable > function that you originally posted. I'm guessing it's the Do loop at the > end. Do you have a version of your code that uses Table (not ParallelTabl= e) > instead of Do? When I substituted the ParallelTable code for the Do loop, > and changed ParallelTable to Table, the code didn't run due to other erro= rs > (your equations aren't simplifying). Try to get Table to work first (it o= nly > needs to go through one iteration, not all n iterations), then change it = to > ParallelTable. > > -Zach > > > On 7/15/2009 10:16 AM, Iv=E1n Lazaro wrote: > > This is the almost complete code without parallelization. Thanks for all > the answers. > > > Num = 4; > Time = 600; > > > r[r4_] := {1, 1, 1, r4}; > A[a13_, a14_, a23_, a24_, a32_, a34_, a42_, > a43_] := {{1, 1, a13, a14}, {1, 1, a23, a24}, {1, a32, 1, > a34}, {1, a42, a43, 1}}; > > > > Variable[] := Flatten[Table[Subscript[x, i][t], {i, 1, Num}]] > > JacobianMatrix[funs_List, vars_List] := Outer[D, funs, vars] > > CondIni[] := Table[{Subscript[x, i][0] == 0.1*i}, {i, 1, Num}] > > Y = Table[{Subscript[x, i][t], Subscript[x, i + 4][t], > Subscript[x, i + 8][t], Subscript[x, i + 12][t]}, {i, 5, 8}]; > > YI9 = Flatten[ > Table[{Subscript[x, i][0] == If[Mod[i, 5] == 0, 1, 0, 0], > Subscript[x, i + 4][0] == If[Mod[i + 4, 5] == 0, 1, 0, 0], > Subscript[x, i + 8][0] == If[Mod[i + 8, 5] == 0, 1, 0, 0], > Subscript[x, i + 12][0] == If[Mod[i + 12, 5] == 0, 1, 0, 0]}= , {i, > 5, 8}]]; > YI3 = Flatten[CondIni[]]; > Ecua[r4_, a13_, a14_, a23_, a24_,a32_, > a34_, a42_, a43_] := > Flatten[Table[ > r[r4][[i]]* > Subscript[x, i][ > t]*(1 - Sum[ > A[a13, a14, a23, a24,a32, a34, a42, > a43][[i, j]] *Subscript[x, j][t], {j, 1, Num}]), {i, 1, > Num}]] ; > > > > Do[ > > > J = JacobianMatrix[ > Ecua[r4_, a13_, a14_, a23_, a24_,a32_, > a34_, a42_, a43_], Variable[]]; > > E1 = Flatten[Transpose[J.Y]]; > > EQ3 = Table[ > D[Subscript[x, i][t], {t, 1}] == > Ecua[r4_, a13_, a14_, a23_, a24_,a32_, > a34_, a42_, a43_][[i]], {i, 1, 4}]; > > EQ9 = Table[D[Subscript[x, i][t], {t, 1}] == E1[[i - 4]], {i, 5, 2= 0}]; > > sol = NDSolve[Join[EQ9, EQ3, YI3, YI9], > Table[Subscript[x, i][t], {i, 1, 20}], {t, 0, Time}, > MaxSteps -> Infinity, AccuracyGoal -> 2]; > > PhiT = Table[{Subscript[x, i][t], Subscript[x, i + 4][t], > Subscript[x, i + 8][t], Subscript[x, i + 12][t]}, {i, 5, > 8}] /. sol /. t -> Time]; > > EL=Log[PhiT] > > If[EL > 0, > PutAppend[Join[A[a13, a14, a23, a24,a32, a34, a42, a43], > r[r4], EL],"File"]], > > > {a13, 0, 2.00, 0.01}, {a14, 0, 2.00, 0.01}, {a23, 0, 2.00, 0.01}, {a24, = 0, > 2.00, > 0.01}, {a32, 0, 2.00, 0.01}, {a34, 0, 2.00, 0.01}, {a42, 0, 2.00, 0.01}= , > {a43, 0, 2.00, > 0.01}, {r4, 0.01, 0.50, 0.01}] > > > > 2009/7/14 Zach Bj=F8rnson <bjornson at mit.edu> > >> Hi- Can you send me your notebook so I can play with it, please? -Zach >> >> On 7/14/2009 3:45 PM, Iv=E1n Lazaro wrote: >> >>> Thanks for the answer. >>> >>> I tried that, but did't work. >>> >>> A and r, are a 4x4 matrix and a vector, respectivily. Ecua[] simply >>> construct equations for NDSolve, and Variables[] do the same. JacobianM= atrix >>> make the Jacobian of equations given by Ecua, using the variables >>> Variable[]. EQ3, EQ9, YI3, YI9 are simply defintions of equations to be >>> given to NDSolve a 3-dimensional system of equations and a 9-dimensiona= l >>> respectivly. >>> >>> The problem i'm triyng to resolve is very time consuming, so I expected >>> that parallelizing could make it faster. As an alternative, i tried wit= h Do >>> instead of Table (and ParallelDo instead of ParallelTable), but the err= or >>> doesn't disapper. The problem seems to be in NDSolve; maybe is not posi= ble >>> parallelize many NDSolve solutions, altought they are not related. >>> >> >
- References:
- ParallelTable doesn't work, but Table does
- From: Iván Lazaro <gaminster@gmail.com>
- ParallelTable doesn't work, but Table does