本文整理汇总了Golang中github.com/cpmech/gosl/mpi.Start函数的典型用法代码示例。如果您正苦于以下问题:Golang Start函数的具体用法?Golang Start怎么用?Golang Start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// catch errors
var tst testing.T
defer func() {
if mpi.Rank() == 0 {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
if tst.Failed() {
io.PfRed("test failed\n")
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// start global variables and log
analysis := fem.NewFEM("data/bh16.sim", "", true, true, false, true, true, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Error("Run failed\n")
return
}
// check
skipK := true
tolK := 1e-12
tolu := 1e-15
tols := 1e-12
fem.TestingCompareResultsU(&tst, "data/bh16.sim", "cmp/bh16.cmp", "", tolK, tolu, tols, skipK, true)
}
示例2: main
func main() {
// catch errors
var tst testing.T
defer func() {
if mpi.Rank() == 0 {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
if tst.Failed() {
io.PfRed("test failed\n")
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// start global variables and log
analysis := fem.NewFEM("data/p01.sim", "", true, true, false, true, true, 0)
// run simulation
err := analysis.Run()
if err != nil {
tst.Error("Run failed\n")
return
}
}
示例3: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
if mpi.Rank() == 0 {
io.PfYel("\nTest MPI 03\n")
}
if mpi.Size() != 3 {
chk.Panic("this test needs 3 processors")
}
x := []int{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
n := len(x)
id, sz := mpi.Rank(), mpi.Size()
start, endp1 := (id*n)/sz, ((id+1)*n)/sz
for i := start; i < endp1; i++ {
x[i] = i
}
//io.Pforan("x = %v\n", x)
// IntAllReduceMax
w := make([]int, n)
mpi.IntAllReduceMax(x, w)
var tst testing.T
chk.Ints(&tst, fmt.Sprintf("IntAllReduceMax: x @ proc # %d", id), x, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
//io.Pfred("x = %v\n", x)
}
示例4: main
func main() {
// catch errors
var tst testing.T
defer func() {
if mpi.Rank() == 0 {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
if tst.Failed() {
io.PfRed("test failed\n")
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// start global variables and log
if !fem.Start("data/p01.sim", true, true) {
tst.Error("Start failed\n")
return
}
// make sure to flush log
defer fem.End()
// run simulation
if !fem.Run() {
tst.Error("Run failed\n")
return
}
}
示例5: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
myrank := mpi.Rank()
if myrank == 0 {
chk.PrintTitle("Test MUMPS Sol 01a")
}
var t la.Triplet
switch mpi.Size() {
case 1:
t.Init(5, 5, 13)
t.Put(0, 0, 1.0)
t.Put(0, 0, 1.0)
t.Put(1, 0, 3.0)
t.Put(0, 1, 3.0)
t.Put(2, 1, -1.0)
t.Put(4, 1, 4.0)
t.Put(1, 2, 4.0)
t.Put(2, 2, -3.0)
t.Put(3, 2, 1.0)
t.Put(4, 2, 2.0)
t.Put(2, 3, 2.0)
t.Put(1, 4, 6.0)
t.Put(4, 4, 1.0)
case 2:
if myrank == 0 {
t.Init(5, 5, 6)
t.Put(0, 0, 1.0)
t.Put(0, 0, 1.0)
t.Put(1, 0, 3.0)
t.Put(0, 1, 3.0)
t.Put(2, 1, -1.0)
t.Put(4, 1, 4.0)
} else {
t.Init(5, 5, 7)
t.Put(1, 2, 4.0)
t.Put(2, 2, -3.0)
t.Put(3, 2, 1.0)
t.Put(4, 2, 2.0)
t.Put(2, 3, 2.0)
t.Put(1, 4, 6.0)
t.Put(4, 4, 1.0)
}
default:
chk.Panic("this test needs 1 or 2 procs")
}
b := []float64{8.0, 45.0, -3.0, 3.0, 19.0}
x_correct := []float64{1, 2, 3, 4, 5}
sum_b_to_root := false
la.RunMumpsTestR(&t, 1e-14, b, x_correct, sum_b_to_root)
}
示例6: main
func main() {
// catch errors
defer func() {
if err := recover(); err != nil {
if mpi.Rank() == 0 {
chk.Verbose = true
for i := 8; i > 3; i-- {
chk.CallerInfo(i)
}
io.PfRed("ERROR: %v\n", err)
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// default input parameters
// read input parameters
fnamepath, _ := io.ArgToFilename(0, "", ".sim", true)
verbose := io.ArgToBool(1, true)
erasePrev := io.ArgToBool(2, true)
saveSummary := io.ArgToBool(3, true)
allowParallel := io.ArgToBool(4, true)
alias := io.ArgToString(5, "")
// message
if mpi.Rank() == 0 && verbose {
io.PfWhite("\nGofem v3 -- Go Finite Element Method\n\n")
io.Pf("Copyright 2015 Dorival Pedroso and Raul Durand. All rights reserved.\n")
io.Pf("Use of this source code is governed by a BSD-style\n")
io.Pf("license that can be found in the LICENSE file.\n\n")
io.Pf("\n%v\n", io.ArgsTable(
"filename path", "fnamepath", fnamepath,
"show messages", "verbose", verbose,
"erase previous results", "erasePrev", erasePrev,
"save summary", "saveSummary", saveSummary,
"allow parallel run", "allowParallel", allowParallel,
"word to add to results", "alias", alias,
))
}
// profiling?
defer utl.DoProf(false)()
// analysis data
readSummary := false
analysis := fem.NewFEM(fnamepath, alias, erasePrev, saveSummary, readSummary, allowParallel, verbose, 0)
// run simulation
err := analysis.Run()
if err != nil {
chk.Panic("Run failed:\n%v", err)
}
}
示例7: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
if mpi.Rank() == 0 {
chk.PrintTitle("Test SumToRoot 01")
}
M := [][]float64{
{1000, 1000, 1000, 1011, 1021, 1000},
{1000, 1000, 1000, 1012, 1022, 1000},
{1000, 1000, 1000, 1013, 1023, 1000},
{1011, 1012, 1013, 1000, 1000, 1000},
{1021, 1022, 1023, 1000, 1000, 1000},
{1000, 1000, 1000, 1000, 1000, 1000},
}
id, sz, m := mpi.Rank(), mpi.Size(), len(M)
start, endp1 := (id*m)/sz, ((id+1)*m)/sz
if sz > 6 {
chk.Panic("this test works with at most 6 processors")
}
var J la.Triplet
J.Init(m, m, m*m)
for i := start; i < endp1; i++ {
for j := 0; j < m; j++ {
J.Put(i, j, M[i][j])
}
}
la.PrintMat(fmt.Sprintf("J @ proc # %d", id), J.ToMatrix(nil).ToDense(), "%10.1f", false)
la.SpTriSumToRoot(&J)
var tst testing.T
if mpi.Rank() == 0 {
chk.Matrix(&tst, "J @ proc 0", 1.0e-17, J.ToMatrix(nil).ToDense(), [][]float64{
{1000, 1000, 1000, 1011, 1021, 1000},
{1000, 1000, 1000, 1012, 1022, 1000},
{1000, 1000, 1000, 1013, 1023, 1000},
{1011, 1012, 1013, 1000, 1000, 1000},
{1021, 1022, 1023, 1000, 1000, 1000},
{1000, 1000, 1000, 1000, 1000, 1000},
})
}
}
示例8: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
if mpi.Rank() == 0 {
chk.PrintTitle("TestJacobian 02b (MPI)")
}
if mpi.Size() > 6 {
io.Pf("this tests works with 6 or less MPI processors\n")
return
}
ffcn := func(fx, x []float64) error {
fx[0] = 2.0*x[0] - x[1] + sin(x[2]) - cos(x[3]) - x[5]*x[5] - 1.0 // 0
fx[1] = -x[0] + 2.0*x[1] + cos(x[2]) - sin(x[3]) + x[5] - 1.0 // 1
fx[2] = x[0] + 3.0*x[1] + sin(x[3]) - cos(x[4]) - x[5]*x[5] - 1.0 // 2
fx[3] = 2.0*x[0] + 4.0*x[1] + cos(x[3]) - cos(x[4]) + x[5] - 1.0 // 3
fx[4] = x[0] + 5.0*x[1] - sin(x[2]) + sin(x[4]) - x[5]*x[5]*x[5] - 1.0 // 4
fx[5] = x[0] + 6.0*x[1] - cos(x[2]) + cos(x[4]) + x[5] - 1.0 // 5
return nil
}
Jfcn := func(dfdx *la.Triplet, x []float64) error {
dfdx.Start()
J := [][]float64{
{2.0, -1.0, cos(x[2]), sin(x[3]), 0.0, -2.0 * x[5]},
{-1.0, 2.0, -sin(x[2]), -cos(x[3]), 0.0, 1.0},
{1.0, 3.0, 0.0, cos(x[3]), sin(x[4]), -2.0 * x[5]},
{2.0, 4.0, 0.0, -sin(x[3]), sin(x[4]), 1.0},
{1.0, 5.0, -cos(x[2]), 0.0, cos(x[4]), -3.0 * x[5] * x[5]},
{1.0, 6.0, sin(x[2]), 0.0, -sin(x[4]), 1.0},
}
id, sz, ndim := mpi.Rank(), mpi.Size(), 6
start, endp1 := (id*ndim)/sz, ((id+1)*ndim)/sz
for col := 0; col < 6; col++ {
for row := start; row < endp1; row++ {
dfdx.Put(row, col, J[row][col])
}
}
//la.PrintMat(fmt.Sprintf("J @ %d",mpi.Rank()), dfdx.ToMatrix(nil).ToDense(), "%12.6f", false)
return nil
}
x := []float64{5.0, 5.0, pi, pi, pi, 5.0}
var tst testing.T
num.CompareJac(&tst, ffcn, Jfcn, x, 1e-6, true)
}
示例9: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
myrank := mpi.Rank()
if myrank == 0 {
chk.PrintTitle("Test MUMPS Sol 05")
}
ndim := 10
id, sz := mpi.Rank(), mpi.Size()
start, endp1 := (id*ndim)/sz, ((id+1)*ndim)/sz
if mpi.Size() > ndim {
chk.Panic("the number of processors must be smaller than or equal to %d", ndim)
}
n := 10
b := make([]complex128, n)
x_correct := make([]complex128, n)
// Let exact solution = 1 + 0.5i
for i := 0; i < ndim; i++ {
x_correct[i] = complex(float64(i+1), float64(i+1)/10.0)
}
var t la.TripletC
t.Init(ndim, ndim, ndim, true)
// assemble a and b
for i := start; i < endp1; i++ {
// Some very fake diagonals. Should take exactly 20 GMRES steps
ar := 10.0 + float64(i)/(float64(ndim)/10.0)
ac := 10.0 - float64(i)/(float64(ndim)/10.0)
t.Put(i, i, ar, ac)
// Generate RHS to match exact solution
b[i] = complex(ar*real(x_correct[i])-ac*imag(x_correct[i]),
ar*imag(x_correct[i])+ac*real(x_correct[i]))
}
sum_b_to_root := true
la.RunMumpsTestC(&t, 1e-14, b, x_correct, sum_b_to_root)
}
示例10: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
if mpi.Rank() == 0 {
chk.PrintTitle("TestJacobian 01b (MPI)")
}
if mpi.Size() != 2 {
io.Pf("this tests needs MPI 2 processors\n")
return
}
ffcn := func(fx, x []float64) error {
fx[0] = math.Pow(x[0], 3.0) + x[1] - 1.0
fx[1] = -x[0] + math.Pow(x[1], 3.0) + 1.0
return nil
}
Jfcn := func(dfdx *la.Triplet, x []float64) error {
dfdx.Start()
if false {
if mpi.Rank() == 0 {
dfdx.Put(0, 0, 3.0*x[0]*x[0])
dfdx.Put(1, 0, -1.0)
} else {
dfdx.Put(0, 1, 1.0)
dfdx.Put(1, 1, 3.0*x[1]*x[1])
}
} else {
if mpi.Rank() == 0 {
dfdx.Put(0, 0, 3.0*x[0]*x[0])
dfdx.Put(0, 1, 1.0)
} else {
dfdx.Put(1, 0, -1.0)
dfdx.Put(1, 1, 3.0*x[1]*x[1])
}
}
return nil
}
x := []float64{0.5, 0.5}
var tst testing.T
num.CompareJacMpi(&tst, ffcn, Jfcn, x, 1e-8, true)
}
示例11: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
myrank := mpi.Rank()
if myrank == 0 {
chk.PrintTitle("Test MUMPS Sol 04")
}
ndim := 10
id, sz := mpi.Rank(), mpi.Size()
start, endp1 := (id*ndim)/sz, ((id+1)*ndim)/sz
if mpi.Size() > ndim {
chk.Panic("the number of processors must be smaller than or equal to %d", ndim)
}
b := make([]complex128, ndim)
var t la.TripletC
t.Init(ndim, ndim, ndim*ndim, true)
for i := start; i < endp1; i++ {
j := i
if i > 0 {
j = i - 1
}
for ; j < 10; j++ {
val := 10.0 - float64(j)
if i > j {
val -= 1.0
}
t.Put(i, j, val, 0)
}
b[i] = complex(float64(i+1), 0.0)
}
x_correct := []complex128{-1, 8, -65, 454, -2725, 13624, -54497, 163490, -326981, 326991}
sum_b_to_root := true
la.RunMumpsTestC(&t, 1e-4, b, x_correct, sum_b_to_root)
}
示例12: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
if mpi.Rank() == 0 {
io.PfYel("\nTest MPI 04\n")
}
for i := 0; i < 60; i++ {
time.Sleep(1e9)
io.Pf("hello from %v\n", mpi.Rank())
if mpi.Rank() == 2 && i == 3 {
io.PfGreen("rank = 3 wants to abort (the following error is OK)\n")
mpi.Abort()
}
}
}
示例13: main
func main() {
// catch errors
var tst testing.T
defer func() {
if mpi.Rank() == 0 {
if err := recover(); err != nil {
io.PfRed("ERROR: %v\n", err)
}
if tst.Failed() {
io.PfRed("test failed\n")
}
}
mpi.Stop(false)
}()
mpi.Start(false)
// start global variables and log
if !fem.Start("data/spo751.sim", true, true) {
tst.Error("Start failed\n")
return
}
// make sure to flush log
defer fem.End()
// run simulation
if !fem.Run() {
tst.Error("Run failed\n")
return
}
// check
skipK := true
tolK := 1e-17
tolu := 1e-12
tols := 1e-14
fem.TestingCompareResultsU(&tst, "data/spo751.sim", "cmp/spo751.cmp", tolK, tolu, tols, skipK, true)
}
示例14: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
if mpi.Rank() == 0 {
chk.PrintTitle("ode02: Hairer-Wanner VII-p5 Eq.(1.5) Van der Pol's Equation")
}
if mpi.Size() != 2 {
chk.Panic(">> error: this test requires 2 MPI processors\n")
return
}
eps := 1.0e-6
w := make([]float64, 2) // workspace
fcn := func(f []float64, dx, x float64, y []float64, args ...interface{}) error {
f[0], f[1] = 0, 0
switch mpi.Rank() {
case 0:
f[0] = y[1]
case 1:
f[1] = ((1.0-y[0]*y[0])*y[1] - y[0]) / eps
}
// join all f
mpi.AllReduceSum(f, w)
return nil
}
jac := func(dfdy *la.Triplet, dx, x float64, y []float64, args ...interface{}) error {
if dfdy.Max() == 0 {
dfdy.Init(2, 2, 4)
}
dfdy.Start()
if false { // per column
switch mpi.Rank() {
case 0:
dfdy.Put(0, 0, 0.0)
dfdy.Put(1, 0, (-2.0*y[0]*y[1]-1.0)/eps)
case 1:
dfdy.Put(0, 1, 1.0)
dfdy.Put(1, 1, (1.0-y[0]*y[0])/eps)
}
} else { // per row
switch mpi.Rank() {
case 0:
dfdy.Put(0, 0, 0.0)
dfdy.Put(0, 1, 1.0)
case 1:
dfdy.Put(1, 0, (-2.0*y[0]*y[1]-1.0)/eps)
dfdy.Put(1, 1, (1.0-y[0]*y[0])/eps)
}
}
return nil
}
// method and flags
silent := false
fixstp := false
//method := "Dopri5"
method := "Radau5"
numjac := false
xa, xb := 0.0, 2.0
ya := []float64{2.0, -0.6}
ndim := len(ya)
// structure to hold numerical results
res := ode.Results{Method: method}
// allocate ODE object
var o ode.Solver
o.Distr = true
if numjac {
o.Init(method, ndim, fcn, nil, nil, ode.SimpleOutput, silent)
} else {
o.Init(method, ndim, fcn, jac, nil, ode.SimpleOutput, silent)
}
// tolerances and initial step size
rtol := 1e-4
atol := rtol
o.IniH = 1.0e-4
o.SetTol(atol, rtol)
//o.NmaxSS = 2
// solve problem
y := make([]float64, ndim)
copy(y, ya)
t0 := time.Now()
if fixstp {
o.Solve(y, xa, xb, 0.05, fixstp, &res)
} else {
o.Solve(y, xa, xb, xb-xa, fixstp, &res)
}
// plot
if mpi.Rank() == 0 {
io.Pfmag("elapsed time = %v\n", time.Now().Sub(t0))
plt.SetForEps(1.5, 400)
args := "'b-', marker='.', lw=1, ms=4, clip_on=0"
//.........这里部分代码省略.........
示例15: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
if mpi.Rank() == 0 {
chk.PrintTitle("Test ODE 02b")
io.Pfcyan("Hairer-Wanner VII-p5 Eq.(1.5) Van der Pol's Equation (MPI)\n")
}
if mpi.Size() != 2 {
chk.Panic(">> error: this test requires 2 MPI processors\n")
return
}
eps := 1.0e-6
w := make([]float64, 2) // workspace
fcn := func(f []float64, x float64, y []float64, args ...interface{}) error {
f[0], f[1] = 0, 0
switch mpi.Rank() {
case 0:
f[0] = y[1]
case 1:
f[1] = ((1.0-y[0]*y[0])*y[1] - y[0]) / eps
}
// join all f
mpi.AllReduceSum(f, w)
return nil
}
jac := func(dfdy *la.Triplet, x float64, y []float64, args ...interface{}) error {
if dfdy.Max() == 0 {
dfdy.Init(2, 2, 4)
}
dfdy.Start()
if false { // per column
switch mpi.Rank() {
case 0:
dfdy.Put(0, 0, 0.0)
dfdy.Put(1, 0, (-2.0*y[0]*y[1]-1.0)/eps)
case 1:
dfdy.Put(0, 1, 1.0)
dfdy.Put(1, 1, (1.0-y[0]*y[0])/eps)
}
} else { // per row
switch mpi.Rank() {
case 0:
dfdy.Put(0, 0, 0.0)
dfdy.Put(0, 1, 1.0)
case 1:
dfdy.Put(1, 0, (-2.0*y[0]*y[1]-1.0)/eps)
dfdy.Put(1, 1, (1.0-y[0]*y[0])/eps)
}
}
return nil
}
// data
silent := false
fixstp := false
//method := "Dopri5"
method := "Radau5"
xa, xb := 0.0, 2.0
ya := []float64{2.0, -0.6}
ndim := len(ya)
// output
var b bytes.Buffer
out := func(first bool, dx, x float64, y []float64, args ...interface{}) error {
if mpi.Rank() == 0 {
if first {
fmt.Fprintf(&b, "%23s %23s %23s %23s\n", "dx", "x", "y0", "y1")
}
fmt.Fprintf(&b, "%23.15E %23.15E %23.15E %23.15E\n", dx, x, y[0], y[1])
}
return nil
}
defer func() {
if mpi.Rank() == 0 {
extra := "d2 = Read('data/vdpol_radau5_for.dat')\n" +
"subplot(3,1,1)\n" +
"plot(d2['x'],d2['y0'],'k+',label='res',ms=10)\n" +
"subplot(3,1,2)\n" +
"plot(d2['x'],d2['y1'],'k+',label='res',ms=10)\n"
ode.Plot("/tmp/gosl", "vdpolB", method, &b, []int{0, 1}, ndim, nil, xa, xb, true, false, extra)
}
}()
// one run
var o ode.ODE
o.Distr = true
//numjac := true
numjac := false
if numjac {
o.Init(method, ndim, fcn, nil, nil, out, silent)
} else {
o.Init(method, ndim, fcn, jac, nil, out, silent)
}
// tolerances and initial step size
//.........这里部分代码省略.........