diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ed4d5fc..2e68fd8 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,6 +1,5 @@ # FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 -FROM mcr.microsoft.com/devcontainers/go:1-1.24-bookworm - +FROM mcr.microsoft.com/devcontainers/go # ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" # Optionally install the cmake for vcpkg @@ -21,6 +20,16 @@ RUN ./configure CC=/usr/bin/mpicc CXX=/usr/bin/mpicxx RUN make && make install RUN go install golang.org/x/tools/cmd/stringer@latest +# Install gofumpt for stricter formatting +RUN go install mvdan.cc/gofumpt@latest + +# Remove ESLint extension if it exists in the base image +RUN find /vscode -name "*eslint*" -type d -exec rm -rf {} + 2>/dev/null || true +RUN find /home/vscode -name "*eslint*" -type d -exec rm -rf {} + 2>/dev/null || true + +# Fix permissions for Go module cache +RUN chown -R vscode:golang /go/pkg + # RUN update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-19 100 # RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-19 100 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 210dc1c..520007a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,21 +4,18 @@ "name": "Go", "build": { "dockerfile": "Dockerfile" - } - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - // "image": "mcr.microsoft.com/devcontainers/go:1-1.24-bookworm" - - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "go version", - + }, // Configure tool-specific properties. - // "customizations": {}, + "customizations": { + "vscode": { + "extensions": [ + "golang.go", + "github.copilot", + "github.copilot-chat", + "-dbaeumer.vscode-eslint" + ] + } + } // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5f561c2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,17 @@ +{ + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file", + "go.formatTool": "gofumpt", + "go.useLanguageServer": true, + "[go]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "golang.go", + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + } + }, + "gopls": { + "gofumpt": true + }, + "files.autoSave": "off" +} diff --git a/cmd/latency.go b/cmd/latency.go index 56f6e68..5c05b23 100644 --- a/cmd/latency.go +++ b/cmd/latency.go @@ -22,12 +22,12 @@ func main() { } myId := o.Rank() // line 49 - for size := 1; size <= maxsize; size *=2 { + for size := 1; size <= maxsize; size *= 2 { var t_total float64 s_buf := []byte(strings.Repeat("a", size)) r_buf := []byte(strings.Repeat("b", size)) o.Barrier() - for iter := range (warmup + iterations) { + for iter := range warmup + iterations { notime := iter < warmup switch myId { diff --git a/flags.go b/flags.go index 41605ca..8dca81a 100644 --- a/flags.go +++ b/flags.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build !windows // +build !windows package mpi diff --git a/mpi.go b/mpi.go index 15c48f9..12b8d92 100644 --- a/mpi.go +++ b/mpi.go @@ -169,7 +169,8 @@ func (s *Status) GetTag() int { } // IsOn tells whether MPI is on or not -// NOTE: this returns true even after Stop +// +// NOTE: this returns true even after Stop func IsOn() bool { var flag C.int C.MPI_Initialized(&flag) @@ -220,8 +221,9 @@ type Communicator struct { } // NewCommunicator creates a new communicator or returns the World communicator -// ranks -- World indices of processors in this Communicator. -// use nil or empty to get the World Communicator +// +// ranks -- World indices of processors in this Communicator. +// use nil or empty to get the World Communicator func NewCommunicator(ranks []int) *Communicator { var o Communicator if len(ranks) == 0 { @@ -720,7 +722,7 @@ func (o *Communicator) RecvComplex128s(fromID int, tag int) ([]complex128, Statu return buf, status } -////////////////////////////////////////////////////////////////////////////// +// //////////////////////////////////////////////////////////////////////////// // SendByte sends one byte to processor toID with given tag func (o *Communicator) SendByte(v byte, toID int, tag int) { buf := unsafe.Pointer(&v) diff --git a/mpi_test.go b/mpi_test.go index a00c4f8..557358e 100644 --- a/mpi_test.go +++ b/mpi_test.go @@ -74,6 +74,7 @@ func setSliceFloat32(x []float32, rank int, offset float32) { } } } + func setSliceFloat64(x []float64, rank int, offset float64) { for i := 0; i < len(x); i++ { if i == rank { @@ -204,7 +205,7 @@ func bcast(A *Communicator) func(*testing.T) { b[i] = byte(1 + i) } } - var exp = []byte{1, 2, 3, 4} + exp := []byte{1, 2, 3, 4} A.BcastBytes(b, root) if !chkArraysEqualByte(b, exp) { t.Errorf("received %v, expected %v", b, exp) @@ -219,7 +220,7 @@ func bcast(A *Communicator) func(*testing.T) { u32[i] = uint32(1 + i) } } - var exp = []uint32{1, 2, 3, 4} + exp := []uint32{1, 2, 3, 4} A.BcastUint32s(u32, root) if !chkArraysEqualUint32(u32, exp) { t.Errorf("received %v, expected %v", u32, exp) @@ -234,12 +235,11 @@ func bcast(A *Communicator) func(*testing.T) { i32[i] = int32(1 + i) } } - var exp = []int32{1, 2, 3, 4} + exp := []int32{1, 2, 3, 4} A.BcastInt32s(i32, root) if !chkArraysEqualInt32(i32, exp) { t.Errorf("received %v, expected %v", i32, exp) } - }) A.Barrier() @@ -265,7 +265,7 @@ func bcast(A *Communicator) func(*testing.T) { i64[i] = int64(1 + i) } } - var exp = []int64{1, 2, 3, 4} + exp := []int64{1, 2, 3, 4} A.BcastInt64s(i64, root) if !chkArraysEqualInt64(i64, exp) { t.Errorf("received %v, expected %v", i64, exp) @@ -280,7 +280,7 @@ func bcast(A *Communicator) func(*testing.T) { f32[i] = float32(1 + i) } } - var exp = []float32{1, 2, 3, 4} + exp := []float32{1, 2, 3, 4} A.BcastFloat32s(f32, root) if !chkArraysEqualFloat32(f32, exp) { t.Errorf("received %v, expected %v", f32, exp) @@ -295,7 +295,7 @@ func bcast(A *Communicator) func(*testing.T) { f64[i] = float64(1 + i) } } - var exp = []float64{1, 2, 3, 4} + exp := []float64{1, 2, 3, 4} A.BcastFloat64s(f64, root) if !chkArraysEqualFloat64(f64, exp) { t.Errorf("received %v, expected %v", f64, exp) @@ -310,7 +310,7 @@ func bcast(A *Communicator) func(*testing.T) { c128[i] = complex(float64(1+i), float64(i)) } } - var exp = []complex128{complex(1, 0), complex(2, 1), complex(3, 2), complex(4, 3)} + exp := []complex128{complex(1, 0), complex(2, 1), complex(3, 2), complex(4, 3)} A.BcastComplex128s(c128, root) if !chkArraysEqualComplex128(c128, exp) { t.Errorf("received %v, expected %v", c128, exp) @@ -609,7 +609,7 @@ func reduce(A *Communicator) func(*testing.T) { {}, // min - not tested {}, // max - not tested - {(2.2 - 1.8i), (4.4 - 3.6i), (6.6 - 5.4i), (8.8 - 7.199999999999999i)}, //prod + {(2.2 - 1.8i), (4.4 - 3.6i), (6.6 - 5.4i), (8.8 - 7.199999999999999i)}, // prod {}, // prod - not tested {}, // land - not tested {}, // lor - not tested @@ -645,6 +645,7 @@ func reduce(A *Communicator) func(*testing.T) { } } } + func allreduce(A *Communicator) func(*testing.T) { root := 3 testNames := [...]string{ @@ -913,7 +914,7 @@ func allreduce(A *Communicator) func(*testing.T) { {}, // min - not tested {}, // max - not tested - {(2.2 - 1.8i), (4.4 - 3.6i), (6.6 - 5.4i), (8.8 - 7.199999999999999i)}, //prod + {(2.2 - 1.8i), (4.4 - 3.6i), (6.6 - 5.4i), (8.8 - 7.199999999999999i)}, // prod {}, // prod - not tested {}, // land - not tested {}, // lor - not tested