#region License Information /* HeuristicLab * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.Optimization; namespace HeuristicLab.Operators.MPISupport { [Item("MPIUnidirectionalRingMigrator", "A unidirectional ring migrator that utilizes MPI if available.")] [StorableClass] public class MPIUnidirectionalRingMigrator : SingleSuccessorOperator { [StorableConstructor] private MPIUnidirectionalRingMigrator(bool deserializing) : base(deserializing) { } private MPIUnidirectionalRingMigrator(MPIUnidirectionalRingMigrator original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new MPIUnidirectionalRingMigrator(this, cloner); } public MPIUnidirectionalRingMigrator() : base() { } public static int Channel = 100; public override IOperation Apply() { if (MPI.Communicator.world != null) { int size = MPI.Communicator.world.Size; if (size > 1) { int i = MPI.Communicator.world.Rank; IScope scope = ExecutionContext.Scope; IScope emigrants = scope.SubScopes[1]; scope.SubScopes.Remove(emigrants); int recipent = i + 1; if (recipent == size) recipent = 0; Console.WriteLine("MIGRATE " + i + " TO " + recipent); MPI.Communicator.world.Send>( new MPITransportWrapper(emigrants), recipent, Channel); IScope immigrants = null; int sender = i - 1; if (sender < 0) sender = size - 1; Console.WriteLine("MIGRATE " + i + " FROM " + sender); immigrants = MPI.Communicator.world.Receive>(sender, Channel).InnerItem; scope.SubScopes.Add(immigrants); } } return base.Apply(); } } }