8000 Fix #267: -gpu flag ignored when running multiple input scripts by JonathanMaes · Pull Request #373 · mumax/3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix #267: -gpu flag ignored when running multiple input scripts #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions cmd/mumax3/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func RunQueue(files []string) {
s := NewStateTab(files)
s.PrintTo(os.Stdout)
go s.ListenAndServe(*engine.Flag_port)
fmt.Print("//Realtime queue overview available at http://127.0.0.1", *engine.Flag_port, "\n")
s.Run()
fmt.Println(numOK.get(), "OK, ", numFailed.get(), "failed")
os.Exit(int(exitStatus))
Expand Down Expand Up @@ -81,8 +82,7 @@ func (s *stateTab) Finish(j job) {

// Runs all the jobs in stateTab.
func (s *stateTab) Run() {
nGPU := cu.DeviceGetCount()
idle := initGPUs(nGPU)
idle, nGPU := initGPUs()
for {
gpu := <-idle
addr := fmt.Sprint(":", 35368+gpu)
Expand Down Expand Up @@ -138,16 +138,27 @@ func run(inFile string, gpu int, webAddr string) {
}
}

func initGPUs(nGpu int) chan int {
// Creates a concurrent channel containing the available GPU IDs for jobs.
// Returns the channel and the number of available GPUs for the queue.
func initGPUs() (chan int, int) {
nGpu := cu.DeviceGetCount()
if nGpu == 0 {
log.Fatal("no GPUs available")
panic(0)
}

singleGPU := engine.FlagPassed("gpu")
if singleGPU {
nGpu = 1
}
idle := make(chan int, nGpu)
for i := 0; i < nGpu; i++ {
idle <- i
if singleGPU {
idle <- *engine.Flag_gpu
} else {
for i := 0; i < nGpu; i++ {
idle <- i
}
}
return idle
return idle, nGpu
}

func (s *stateTab) PrintTo(w io.Writer) {
Expand Down
17 changes: 14 additions & 3 deletions engine/gofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ package engine

import (
"flag"
"github.com/mumax/3/cuda"
"github.com/mumax/3/util"
"os"
"path"

"github.com/mumax/3/cuda"
"github.com/mumax/3/util"
)

var (
// These flags are shared between cmd/mumax3 and Go input files.
Flag_cachedir = flag.String("cache", os.TempDir(), "Kernel cache directory (empty disables caching)")
Flag_gpu = flag.Int("gpu", 0, "Specify GPU")
Flag_gpu = flag.Int("gpu", 0, "Specify a single GPU (use CUDA_AVAILABLE_DEVICES environment variable for advanced selection)")
Flag_interactive = flag.Bool("i", false, "Open interactive browser session")
Flag_od = flag.String("o", "", "Override output directory")
Flag_port = flag.String("http", ":35367", "Port to serve web gui")
Expand All @@ -23,6 +24,16 @@ var (
Flag_forceclean = flag.Bool("f", false, "Force start, clean existing output directory")
)

func FlagPassed(name string) bool {
passed := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
passed = true
}
})
return passed
}

// Usage: in every Go input file, write:
//
// func main(){
Expand Down
0