func NewVec(nlocal, nglobal int64) *structvec.StructVec { v, err := structvec.NewStructVec(One{}, nlocal, nglobal) if err != nil { petsc.Fatal(err) } return v }
func main() { // PETSc initialization if err := petsc.Initialize(); err != nil { petsc.Fatal(err) } defer func() { if err := petsc.Finalize(); err != nil { petsc.Fatal(err) } }() rank, size := petsc.RankSize() // Create particles var np1 int64 = 1 if rank == 0 { np1 = 2 } pp, err := structvec.NewStructVec(pstruct{}, np1, petsc.DETERMINE) if err != nil { petsc.Fatal(err) } defer pp.Destroy() lpp, _ := pp.GetArray().([]pstruct) for i := range lpp { for j := 0; j < 3; j++ { lpp[i].pos[j] = (float32(i) + 1) * (float32(j + 1 + rank*10)) } } pp.RestoreArray() lpp, _ = pp.GetArray().([]pstruct) dump(lpp, rank) pp.RestoreArray() // Set up scatters var localndx, mpirank []int64 if rank == 0 { localndx = make([]int64, 1+size) mpirank = make([]int64, 1+size) for i := 0; i < size; i++ { localndx[i] = 0 mpirank[i] = int64(i) } localndx[size] = 1 mpirank[size] = int64((rank + 1) % size) } else { localndx = make([]int64, 1) mpirank = make([]int64, 1) localndx[0] = 0 mpirank[0] = int64((rank + 1) % size) } petsc.Printf("\n\n\n") pp.Scatter(localndx, mpirank) lpp, _ = pp.GetArray().([]pstruct) dump(lpp, rank) pp.RestoreArray() }
func main() { // PETSc initialization if err := petsc.Initialize(); err != nil { petsc.Fatal(err) } defer func() { if err := petsc.Finalize(); err != nil { petsc.Fatal(err) } }() rank, _ := petsc.RankSize() v, err := structvec.NewStructVec(pstruct{}, petsc.DECIDE, 10) if err != nil { petsc.Fatal(err) } defer v.Destroy() petsc.Printf("Type of v : %s\n", v.Type()) petsc.Printf("Size of v : %d\n", v.BlockSize()) petsc.SyncPrintf("Local size = %d\n", v.Nlocal) petsc.SyncFlush() petsc.Printf("Global size = %d\n", v.Ntotal) // local particle data lpp, ok := v.GetArray().([]pstruct) if !ok { petsc.Fatal(err) } for i := range lpp { lpp[i].FillRandom() } err = v.RestoreArray() if err != nil { petsc.Fatal(err) } // Print array lpp, ok = v.GetArray().([]pstruct) if !ok { petsc.Fatal(err) } for i := range lpp { petsc.SyncPrintf("%s\n", lpp[i]) } petsc.SyncFlush() err = v.RestoreArray() if err != nil { petsc.Fatal(err) } petsc.Printf("----------------\n") // Fiddle with array if rank == 0 { lpp = make([]pstruct, 2) ix := []int64{3, 7} err = v.SetValues(ix, lpp) if err != nil { petsc.Fatal(err) } } v.AssemblyBegin() v.AssemblyEnd() // Print array lpp, ok = v.GetArray().([]pstruct) if !ok { petsc.Fatal(err) } for i := range lpp { petsc.SyncPrintf("%s\n", lpp[i]) } petsc.SyncFlush() err = v.RestoreArray() if err != nil { petsc.Fatal(err) } }