示例#1
0
        private static void Process(ExecutionModes executionModes, int degreeOfParalellism = 0)
        {
            var timeSpan = DateTime.Now.TimeOfDay;
            int count    = 0;

            switch (executionModes)
            {
            case ExecutionModes.Sequential:
                count = DataSource.Count(n => n.IsEven());
                break;

            case ExecutionModes.Parallel:

                if (degreeOfParalellism.Equals(0))
                {
                    count = DataSource.AsParallel().Count(n => n.IsEven());
                }
                else
                {
                    count = DataSource.AsParallel().WithDegreeOfParallelism(degreeOfParalellism).Count(n => n.IsEven());
                }

                break;

            default:
                break;
            }

            Log($"Processing with {Enum.GetName(typeof(ExecutionModes), executionModes)}, {degreeOfParalellism} Degrees of paralellism. TimeSpan: {DateTime.Now.TimeOfDay - timeSpan}, for {count} interactions");
        }
示例#2
0
        public string ToStringFormatted()
        {
            var stringBuilder = new StringBuilder();

            foreach (var inst in Instructions)
            {
                stringBuilder.Append($"\t\t{ inst.ToStringFormatted() }\n");
            }
            var instructionString = stringBuilder.ToString();

            stringBuilder.Clear();

            return("Spir-V Source [\n" +
                   $"\tVersion: 0.{ VersionMajor }.{ VersionMinor }.0\n" +
                   $"\tGenerator: { GeneratorMagic }\n" +
                   $"\tBound: { Bound }\n" +
                   $"\tCapabilities: { string.Join(", ", Capabilities ) }\n" +
                   $"\tExtensions: { string.Join(", ", Extensions) }\n" +
                   $"\tExtInstImports: { ExtInstImports.ToStringFormatted() }\n" +
                   $"\tMemoryModel: { MemoryModel }\n" +
                   $"\tEntryPoints: { string.Join(", ", EntryPoints) }\n" +
                   $"\tExecutionModes: { ExecutionModes.ToStringFormatted() }\n" +
                   $"\tNames: { Names.ToStringFormatted() }\n" +
                   $"\tMemberNames: { MemberNames.ToStringFormatted() }\n" +
                   $"\tInstructions:\n" +
                   $"{instructionString}]");
        }
示例#3
0
        public SpirV(Stream stream)
        {
            using (var br = new BinaryReader(stream))
            {
                // Word 0; file magic
                var magic = br.ReadUInt32();
                if (magic != SpirVMagic)
                {
                    throw new InvalidDataException("File magic was incorrect");
                }

                // Word 1; version number
                br.ReadByte();
                VersionMinor = br.ReadByte();
                VersionMajor = br.ReadByte();
                br.ReadByte();

                // Word 2; generator magic
                GeneratorMagic = br.ReadUInt32();

                // Word 3; bound IDs where 0 < ID < this
                Bound = br.ReadInt32();

                // Word 4; optional instruction schema
                br.ReadInt32();

                // Word 5 and beyond; instructions
                Instructions = new List <Instruction>();
                while (stream.Position < stream.Length)
                {
                    var        inst = new Instruction(br);
                    string     sA;
                    int        iA;
                    List <int> lA;
                    switch (inst.OpCode)
                    {
                    case OpCodeID.Capability:
                        Capabilities.Add((Capability)inst[1]);
                        break;

                    case OpCodeID.Extension:
                        Extensions.Add(inst.String(1));
                        break;

                    case OpCodeID.ExtInstImport:
                        ExtInstImports.Add(inst[1], inst.String(2));
                        break;

                    case OpCodeID.MemoryModel:
                        MemoryModel = (MemoryModel)inst[1];
                        break;

                    case OpCodeID.EntryPoint:
                        sA = inst.String(3, out iA);
                        lA = new List <int>();
                        for (var i = iA; i < inst.Length; i++)
                        {
                            lA.Add(inst[i]);
                        }
                        EntryPoints.Add(new EntryPoint((ExecutionModel)inst[1], inst[2], sA, lA));
                        break;

                    case OpCodeID.ExecutionMode:
                        ExecutionModes.Add(inst[1], (ExecutionMode)inst[2]);
                        break;

                    case OpCodeID.Name:
                        Names.Add(inst[1], inst.String(2));
                        MemberNames.Add(inst[1], new Dictionary <int, string>());
                        break;

                    case OpCodeID.MemberName:
                        MemberNames[inst[1]].Add(inst[2], inst.String(3));
                        break;

                    default:
                        Instructions.Add(new Instruction(br));
                        break;
                    }
                }
            }
        }
示例#4
0
 /// <summary>
 /// Takes a change in <see cref="ExecutionModes"/> which is assumed to come from the <see cref="WorkSpace"/> model
 /// and ensures it is matched by the <see cref="View"/>.
 /// </summary>
 /// <param name="source">The <see cref="IWorkSpace"/> from which the change originated.</param>
 /// <param name="newMode">The new <see cref="ExecutionModes"/> setting.</param>
 internal void UpdateExedModeInView(IWorkSpace source, ExecutionModes newMode)
 {
     if (View.ExecMode != newMode)
     {
         View.ExecMode = newMode;
     }
 }
示例#5
0
 /// <summary>
 /// Takes a change in <see cref="ExecutionModes"/> which is assumed to come from the <see cref="View"/>
 /// and ensures it is matched by the <see cref="WorkSpace"/> model.
 /// </summary>
 /// <param name="source">The <see cref="IWorkSpaceView"/> from which the change originated.</param>
 /// <param name="newMode">The new <see cref="ExecutionModes"/> setting.</param>
 internal void UpdateExedModeInModel(IWorkSpaceView source, ExecutionModes newMode)
 {
     if (WorkSpace.ExecMode != newMode)
     {
         WorkSpace.ExecMode = newMode;
     }
 }
示例#6
0
 public WorkSpaceHaltEventArgs(ExecutionModes mode, string message)
 {
     Message = message;
     Mode = mode;
 }
示例#7
0
 public WorkSpaceHaltEventArgs(ExecutionModes mode)
 {
     Mode = mode;
 }
 public WorkSpaceExecModeChangeEventArgs(ExecutionModes currentMode, ExecutionModes newMode, string message)
     : base((int)currentMode, (int)newMode, message)
 {
     CurrentMode = currentMode;
     NewMode = newMode;
 }
示例#9
0
 public ExecModeChangeEventArgs(ExecutionModes currentMode, ExecutionModes newMode)
     : base((int)currentMode, (int)newMode)
 {
     CurrentMode = currentMode;
     NewMode = newMode;
 }