Exemple #1
0
func main() {
	// PETSc initialization
	if err := petscgo.Initialize(); err != nil {
		petscgo.Fatal(err)
	}
	defer func() {
		if err := petscgo.Finalize(); err != nil {
			petscgo.Fatal(err)
		}
	}()
	rank, size := petscgo.RankSize()

	// Create particles
	var np1 int64 = 1
	if rank == 0 {
		np1 = 2
	}
	pp, err := structvec.NewStructVec(pstruct{}, np1, petscgo.DETERMINE)
	if err != nil {
		petscgo.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)
	}

	petscgo.Printf("\n\n\n")
	pp.Scatter(localndx, mpirank)
	lpp, _ = pp.GetArray().([]pstruct)
	dump(lpp, rank)
	pp.RestoreArray()

}
Exemple #2
0
func NewVec(nlocal, nglobal int64) *structvec.StructVec {
	v, err := structvec.NewStructVec(One{}, nlocal, nglobal)
	if err != nil {
		petscgo.Fatal(err)
	}
	return v
}
Exemple #3
0
func main() {
	// PETSc initialization
	if err := petscgo.Initialize(); err != nil {
		petscgo.Fatal(err)
	}
	defer func() {
		if err := petscgo.Finalize(); err != nil {
			petscgo.Fatal(err)
		}
	}()
	rank, _ := petscgo.RankSize()

	v, err := structvec.NewStructVec(pstruct{}, petscgo.DECIDE, 10)
	if err != nil {
		petscgo.Fatal(err)
	}
	defer v.Destroy()
	petscgo.Printf("Type of v : %s\n", v.Type())
	petscgo.Printf("Size of v : %d\n", v.BlockSize())
	petscgo.SyncPrintf("Local size = %d\n", v.Nlocal)
	petscgo.SyncFlush()
	petscgo.Printf("Global size = %d\n", v.Ntotal)

	// local particle data
	lpp, ok := v.GetArray().([]pstruct)
	if !ok {
		petscgo.Fatal(err)
	}
	for i := range lpp {
		lpp[i].FillRandom()
	}
	err = v.RestoreArray()
	if err != nil {
		petscgo.Fatal(err)
	}

	// Print array
	lpp, ok = v.GetArray().([]pstruct)
	if !ok {
		petscgo.Fatal(err)
	}
	for i := range lpp {
		petscgo.SyncPrintf("%s\n", lpp[i])
	}
	petscgo.SyncFlush()
	err = v.RestoreArray()
	if err != nil {
		petscgo.Fatal(err)
	}

	petscgo.Printf("----------------\n")

	// Fiddle with array
	if rank == 0 {
		lpp = make([]pstruct, 2)
		ix := []int64{3, 7}
		err = v.SetValues(ix, lpp)
		if err != nil {
			petscgo.Fatal(err)
		}
	}
	v.AssemblyBegin()
	v.AssemblyEnd()

	// Print array
	lpp, ok = v.GetArray().([]pstruct)
	if !ok {
		petscgo.Fatal(err)
	}
	for i := range lpp {
		petscgo.SyncPrintf("%s\n", lpp[i])
	}
	petscgo.SyncFlush()
	err = v.RestoreArray()
	if err != nil {
		petscgo.Fatal(err)
	}

}