Example #1
0
// Builds a new Computable
// queue: The Message Queue to be used by the worker
// id : the id of the computable
// points: The points to build the Estimator
// smooth: The smoothing parameter of the kernel estimator
func NewComputable(queue mpi.MessagesQueue, id int,
	est models.Estimate) *Computable {
	workerName := string(strconv.AppendInt([]byte("Worker "), int64(id), 10))
	ch := make(chan models.SLPoint)
	queue.Register(workerName)
	queue.Write(workerName, est.State())
	return &Computable{id, workerName, ch, est}
}
Example #2
0
func SimpleWorker(queue mpi.MessagesQueue, cmpt *Computable, tau int) {
	i := 1
	vc := make(map[string]int) // version control map
	for {
		select {
		case data, ok := <-cmpt.Input:
			if !ok {
				return
			}
			if i == 1 {
				for _, v := range queue.Queues() {
					vc[v] = 0
				}
			}
			// ici on va faire des computations
			if i%tau == 0 && tau != 1 {
				stat := queue.ReadStates(vc)
				// Block of code just to covert to the good types
				states := make([]models.State, 0, len(stat))
				for _, v := range stat {
					states = append(states, v.(models.State))
				}
				// We know append the knew versions
				for key, v := range stat {
					vc[key] = v.Version()
				}
				if len(states) != 0 {
					acc := models.States(states).Average()
					cmpt.Est.Average(acc, data)
				} else {
					cmpt.Est.Compute(data)
				}
			} else {
				cmpt.Est.Compute(data)
			}
			queue.Write(cmpt.Name, cmpt.Est.State())
			i = i + 1
		}
	}
}
Example #3
0
func Worker(queue mpi.MessagesQueue, cmpt *models.DistributedSGD, tau int) {
	i := 1

	vc := make(map[string]int) // version control map

	var model1 []float64
	copy(cmpt.Instance.Model(), model1)

	model2 := cmpt.Instance.Model()
	for !cmpt.Stop(model1, model2) {
		if i == 1 {
			for _, v := range queue.Queues() {
				vc[v] = 0
			}
		}
		// ici on va faire des computations
		if i%tau == 0 && tau != 1 {
			stat := queue.ReadStates(vc)
			// Block of code just to covert to the good types
			states := make([]models.State, 0, len(stat))
			for _, v := range stat {
				states = append(states, v.(models.State))
			}
			// We know append the knew versions
			for key, v := range stat {
				vc[key] = v.Version()
			}
			if len(states) != 0 {
				acc := models.States(states)
				cmpt.Average(acc, i)
			}
		} else {
			cmpt.Compute(i)
		}
		queue.Write(cmpt.Name, cmpt.State())
		i = i + 1
	}
}