<|start_filename|>common/chunks.go<|end_filename|>
package common

// MinChunkSize is the global chunksize used for all multi-threading technics
const MinChunkSize int = 4096

// MaxChunkPerCore is the number of chunks per core we want to use
const MaxChunkPerCore int = 1

// ChunkRange is a container for the beginning and the End of a chunk
type ChunkRange struct {
	Begin, End int
}

// IntoChunkRanges returns a list of range of chunks computed for N entries
// Try to do chunks as big as possible with minChunkSize as a minimum
func IntoChunkRanges(nCore, N int) []ChunkRange {
	chunkSize := Max(MinChunkSize, N/(MaxChunkPerCore*nCore))
	// nChunks is the number of jobs (not necessarily simultaneously) to be run
	nChunks := N / chunkSize
	if nChunks*chunkSize < N {
		// handle the case where n is not divisible by chunkSize
		nChunks++
	}

	chunkRanges := make([]ChunkRange, nChunks)
	Begin := 0
	for i := 0; i < nChunks; i++ {
		chunkRanges[i] = ChunkRange{Begin: Begin, End: Min(N, Begin+chunkSize)}
		Begin += chunkSize
	}

	return chunkRanges
}


<|start_filename|>hash/hash.go<|end_filename|>
package hash

func init() {
	initArk()
	initPoseidon()
	initGMimc()
}


<|start_filename|>common/env.go<|end_filename|>
package common

import (
	"fmt"
	"os"
	"strconv"
)

const (
	bNEnv         = "BN_GKR"
	nChunksEnv    = "NCHUNKS_GKR"
	profileEnv    = "PROFILE_GKR"
	traceEnv      = "TRACE_GKR"
	nProcessesEnv = "NPROCESSES_ENV"
	panicMsg      = "Please set %q before running the benchmark"
)

// GetBN attempt to parse the environment variable BN_GKR
// It panics if it's not set
func GetBN() int {
	bN, err := strconv.Atoi(os.Getenv(bNEnv))
	if err != nil {
		panic(fmt.Sprintf(panicMsg, bNEnv))
	}
	return bN
}

// GetNChunks attempts to parse the environment variable NCHUNKS_GKR
// It panics if it's not set'
func GetNChunks() int {
	nChunks, err := strconv.Atoi(os.Getenv(nChunksEnv))
	if err != nil {
		panic(fmt.Sprintf(panicMsg, nChunksEnv))
	}
	return nChunks
}

// GetProfiled attempts to parse the environment variable PROFILE_GKR
// It return false if it's not set or set to a value != 1
func GetProfiled() bool {
	return os.Getenv(profileEnv) == "1"
}

// GetTraced attempts to parse the environment variable PROFILE_GKR
// It return false if it's not set or set to a value != 1
func GetTraced() bool {
	return os.Getenv(traceEnv) == "1"
}

// GetNProcesses returns the env variable and panic if it does not find it
func GetNProcesses() int {
	nProcesses, err := strconv.Atoi(os.Getenv(nProcessesEnv))
	if err != nil {
		panic(fmt.Sprintf(panicMsg, nProcessesEnv))
	}
	return nProcesses
}


<|start_filename|>common/math.go<|end_filename|>
package common

// Min returns the minimum of two numbers
func Min(a int, b int) int {
	if a <= b {
		return a
	}
	return b
}

// Max returns the maximum of two number
func Max(a int, b int) int {
	if a >= b {
		return a
	}
	return b
}

// Log2Floor computes the floored value of Log2
func Log2Floor(a int) int {
	res := 0
	for i := a; i > 1; i = i >> 1 {
		res++
	}
	return res
}

// Log2Ceil computes the ceiled value of Log2
func Log2Ceil(a int) int {
	floor := Log2Floor(a)
	if a != 1<<floor {
		floor++
	}
	return floor
}
