parallels

package module
v0.0.0-...-d20b9d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2016 License: MIT Imports: 7 Imported by: 1

README

parallels

A Go library of parallel operations, algorithms, and primatives

Documentation

Index

Constants

View Source
const (
	InvalidJob = JobStatus(iota) // Could not find job
	Enqueued   = JobStatus(iota) // In the queue, waiting to run
	Running    = JobStatus(iota) // Running
	Terminated = JobStatus(iota) // Error/forced quit
	Completed  = JobStatus(iota) // Completed successfully
)

* The different statuses of a Job

Variables

View Source
var (
	MinWorkPerThread = 16 * 1024
)

Functions

func BatchSize

func BatchSize(newBatchSize int) int

BatchSize returns the batchsize

func Foreach

func Foreach(f func(i int) bool, iterations int)

Foreach mimics a parallel foreach construct

    This code should be equivalent to the serial code:

        for i := 0 ; i < iterations; i++ {
            f(i);
        }

@f          -   Function to call in each iteration of the for loop
@iterations -   How many iterations we should perform

func Map

func Map(data []gotypes.Value, f func(gotypes.Value) gotypes.Value)

Map takes in a function and how many

func Run

func Run(theJobs []Job)

Run takes in an array of jobs and executes them

func StatusByName

func StatusByName(status JobStatus) string

StatusByName returns a status value by its string representation

Types

type IterableJob

type IterableJob struct {
	// contains filtered or unexported fields
}

IterableJob represents the work performed in a loop

func (*IterableJob) GetID

func (j *IterableJob) GetID() int

GetID returns the id for this job.

If the job has been submitted to the runtime then
this ID has been set to some internal ID

func (*IterableJob) GetName

func (j *IterableJob) GetName() string

GetName will return the user given name of this job

func (*IterableJob) Next

func (j *IterableJob) Next() bool

Next will try to perform the next operation for this job

func (*IterableJob) SetID

func (j *IterableJob) SetID(id int)

SetID sets the ID if it has not been set previously

type Job

type Job interface {
	GetName() string
	Next() bool
	GetID() int
	SetID(int)
}

Job which you want to run in parallel

func CreateIterableJob

func CreateIterableJob(name string, f func(i int) bool, currPos int) Job

CreateIterableJob returns a new Iterable Job

type JobStatus

type JobStatus int

JobStatus represents the current status of a job

type Runtime

type Runtime interface {

	// StartJob starts a job and returns a UID
	// for the job
	StartJob(job Job) int

	// StopJob stops the given job
	StopJob(jobID int) bool

	// JobStatus returns the status of the job
	JobStatus(jobID int) JobStatus

	// Start the parallels runtime
	Start()

	// Stop the parallels runtime
	Stop()
}

Runtime handles the parallels runtime

func GetRuntime

func GetRuntime() Runtime

GetRuntime returns the current runtime

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL