示例#1
0
        public void EchoWithDispose()
        {
            var interpreterSettings = new Dictionary <string, string> {
                ["RUNASSERVICE"] = "2",
                ["MAXWS"]        = "1G"
            };

            for (int i = 0; i < 1000; i++)
            {
                var interpreter = new DyalogInterpreter(null, interpreterSettings)
                {
                    SingleThreaded = true,
                    DeleteOnUnload = true
                };

                try {
                    var apl    = new AplGroup001.SubSpace.A1(interpreter);
                    var result = apl.Echo(i);
                    Assert.AreEqual(i, result);
                    apl.Dispose();
                } finally {
                    interpreter.Unload();
                }
            }
        }
 public void CallWithLoopedOperationParallelLateDispose()
 {
     foreach (int innerLoopSize in LoopSizeDefinition)
     {
         List <DyalogInterpreter> interpreters = new List <DyalogInterpreter>();
         Parallel.ForEach(Enumerable.Range(0, TasklLoopSize).ToList(), (counter) => {
             DyalogInterpreter interpreter = new DyalogInterpreter()
             {
                 SingleThreaded = true, DeleteOnUnload = DeleteOnUnload
             };
             lock (interpreters) {
                 interpreters.Add(interpreter);
             }
             try {
                 var apl    = new SimpleAplClass(interpreter);
                 var result = apl.Call(innerLoopSize);
             } catch (Exception) {
             }
         });
         foreach (var interpreter in interpreters)
         {
             interpreter.Unload();
         }
     }
 }
        public void CallWithArgParallelSleepBeforeStartLateDispose()
        {
            List <DyalogInterpreter> interpreters = new List <DyalogInterpreter>();

            Parallel.ForEach(Enumerable.Range(0, TasklLoopSize).ToList(), (counter) => {
                Thread.Sleep(counter * 3);
                DyalogInterpreter interpreter = new DyalogInterpreter()
                {
                    SingleThreaded = true, DeleteOnUnload = DeleteOnUnload
                };
                lock (interpreters) {
                    interpreters.Add(interpreter);
                }
                try {
                    var apl    = new SimpleAplClass(interpreter);
                    var result = apl.CallWithArgument(15);
                    Assert.AreEqual(15, result);
                } catch (Exception) {
                }
            });
            foreach (var interpreter in interpreters)
            {
                interpreter.Unload();
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            // long result;
            // Stopwatch stop;

            var interpreter = new DyalogInterpreter();

            interpreter.SingleThreaded = true;
            interpreter.DeleteOnUnload = true;

            var calc = new Calculator(interpreter);

            // Test good old exit specification (xs)
            // calc.SetStopThis("Sum");
            try {
                var resultUpper = calc.Upper("TestSystemErrors");
                var result      = calc.Sum(new int[0]);
            } catch (AplExitSpecificationException ex) {
                Console.WriteLine("Exception: " + ex.Message);
            }

            // Test Dyalog APL system error - DOMAIN ERROR
            try {
                var result2 = calc.Divide(4, 0);
            } catch (AplDomainErrorException ex) {
                Console.WriteLine("Exception: " + ex.Message);
            }

            var interpreter2 = new DyalogInterpreter();

            interpreter2.SingleThreaded = true;

            using (var test = new ClassWithDispose(interpreter)) {
                // test.SetStopThis("Divide");
                try {
                    var result = test.Divide(4, 0);
                } catch (AplDomainErrorException ex) {
                    Console.WriteLine("Exception: " + ex.Message);
                }
            }
            var test2 = new ClassWithDispose(interpreter2);
            // test.SetStopThis("MakeBigVar");
            var newClass = test2.GetNewInstance(99);

            Console.WriteLine("[]WA: " + test2.WsAwail());
            //test2.ExecuteExpr("#.BigVar←1000 1000⍴⊂'Trala'");
            //var bigvar = test2.ExecuteExprWithResult("#.BigVar");
            //test2.ExecuteExpr("⎕EX'#.BigVar'");
            test2.MakeBigVar(1000, 1000, "Tralala");

            interpreter.Unload();
            (test2 as IDisposable)?.Dispose();
            interpreter2.Unload();
            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();
        }
示例#5
0
        public void DivideByZeroTest()
        {
            var interpreter = new DyalogInterpreter();

            interpreter.SingleThreaded = true;
            interpreter.DeleteOnUnload = true;
            try {
                var test   = new Calculator(interpreter);
                var result = test.Divide(4, 0);
            } finally {
                interpreter.Unload();
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press <ENTER> to begin");
            Console.ReadLine();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("============================< START OF {0:D4} >============================", i);
                var process = Process.GetCurrentProcess();
                var ws      = process.WorkingSet64;
                var pb      = process.PrivateMemorySize64;
                if (i == 0)
                {
                    Init_WS = ws;
                    Init_PB = pb;
                }

                ReportResources(process, "Initial");

                var interpreter = new DyalogInterpreter {
                    SingleThreaded = true,
                    DeleteOnUnload = true
                };

                try {
                    var apl    = new SimpleAplClass(interpreter);
                    int result = apl.CallWithArgument(15);
                    Console.WriteLine("Result from APL: {0}", result);
                } finally {
                    Console.WriteLine("Successfully unloaded interpreter: {0}", interpreter.Unload());
                    ReportResources(process, "After unload");
                }
                Console.WriteLine();
                //Console.ReadLine();
            }

            Console.WriteLine("=================================< END >=================================");
            Console.WriteLine("Initial WS {0,15:N0} bytes", Init_WS);
            Console.WriteLine("Final WS   {0,15:N0} bytes", Prev_WS);
            Console.WriteLine("Diff WS    {0,15:N0} bytes", Prev_WS - Init_WS);

            Console.WriteLine();

            Console.WriteLine("Initial PB {0,15:N0} bytes", Init_PB);
            Console.WriteLine("Final PB   {0,15:N0} bytes", Prev_PB);
            Console.WriteLine("Diff PB    {0,15:N0} bytes", Prev_PB - Init_PB);

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to exit");
            Console.ReadLine();
        }
示例#7
0
        public void APLCoreTest()
        {
            var interpreter = new DyalogInterpreter();

            interpreter.SingleThreaded = true;
            interpreter.DeleteOnUnload = true;
            var test = new TestSystemErrors(interpreter);

            try {
                test.TryCreateAPLCore();
            } finally {
                interpreter.Unload();
            }
        }
        private void CreateAPLObjectCallWithArgAndUnload()
        {
            DyalogInterpreter interpreter = new DyalogInterpreter();

            interpreter.SingleThreaded = true;
            interpreter.DeleteOnUnload = DeleteOnUnload;
            try {
                var apl    = new SimpleAplClass(interpreter);
                int result = apl.CallWithArgument(15);
                Assert.AreEqual(15, result);
            } finally {
                Assert.IsTrue(interpreter.Unload());
            }
        }
示例#9
0
        public void SetAndGetData()
        {
            var interpreter = new DyalogInterpreter();

            interpreter.SingleThreaded = true;
            interpreter.DeleteOnUnload = true;
            try {
                using (var test = new ClassWithDispose(interpreter)) {
                    test.MakeBigVar(1000, 1000, "Tralala");
                    var bigvar = test.GetBigVar();
                    var rank   = ((object[, ])bigvar).Rank;
                    Assert.AreEqual(2, rank);
                }
            } finally {
                interpreter.Unload();
            }
        }
        private void CreateAPLObjectCallWithLoopedOperationAndUnload(int innerLoopSize)
        {
            DyalogInterpreter interpreter = new DyalogInterpreter();

            interpreter.SingleThreaded = true;
            interpreter.DeleteOnUnload = DeleteOnUnload;
            try {
                var apl    = new SimpleAplClass(interpreter);
                int result = apl.Call(innerLoopSize);
                Assert.AreEqual(1, result);
            } /*catch (Exception e) {
               *
               *
               * }
               */finally {
                Assert.IsTrue(interpreter.Unload());
            }
        }
示例#11
0
        public void WSFullTest()
        {
            Dictionary <string, string> confSettings = new Dictionary <string, string>();

            confSettings.Add("maxws", "512K");

            var interpreter = new DyalogInterpreter(null, confSettings);

            interpreter.SingleThreaded = true;
            interpreter.DeleteOnUnload = true;
            using (var test = new ClassWithDispose(interpreter)) {
                try {
                    test.MakeBigVar(1000, 1000, "Tralala");
                    var bigvar = test.GetBigVar();
                } finally {
                    interpreter.Unload();
                }
            }
        }
示例#12
0
        public void NestedInstanceSingleHost()
        {
            var interpreter = new DyalogInterpreter(".\\dyalog180_64_unicode.dll", null)
            {
                SingleThreaded = true,
                DeleteOnUnload = true
            };

            try {
                var apl = new AplGroup003.NestedClassSimpleName(1, interpreter);
                Assert.AreEqual(1, apl.ID());
                Assert.AreEqual(1, apl.ThisID());
                apl.Init();
                Assert.AreEqual(2, apl.ID());
                Assert.AreEqual(2, apl.NestedID());
                Assert.AreEqual(2, apl.ThisID());
            } finally {
                interpreter.Unload();
            }
        }
示例#13
0
        private static DyalogInterpreter CreateInterpreter(string[] codeFiles = null)
        {
            var interpreterSettings = new Dictionary <string, string> {
                ["RUNASSERVICE"] = "2",
                ["MAXWS"]        = "1G"
            };
            var interpreter = new DyalogInterpreter(null, interpreterSettings)
            {
                SingleThreaded  = true,
                DeleteOnUnload  = true,
                UnloadWhenEmpty = false
            };

            if (codeFiles != null)
            {
                var aplc = new CodeFile(interpreter);
                aplc.AttachCodeFiles(codeFiles);
                aplc.Dispose();
            }
            return(interpreter);
        }
示例#14
0
        public static void RunAndTrace(bool usecodefile = false)
        {
            var process   = Process.GetCurrentProcess();
            var stopwatch = new Stopwatch();
            var fn        = "externalcodefile";
            var ext       = usecodefile ? ".dwx" : ".dws";

            Console.WriteLine($"Run and trace using {(usecodefile ? "codefile" : "standard dws")} {fn}{ext}.");

            var file     = Path.Combine(Path.GetTempPath(), fn);
            var codefile = $"{file}{ext}";

            CreateCodeFiles(file);
            //if (File.Exists(codefile)) File.Delete(codefile);
            //var interpreterc = CreateInterpreter();
            //var aplcc = new CodeFile(interpreterc);
            //aplcc.CreateLargeCache(codefile);
            //aplcc.Dispose();
            //interpreterc.Unload();

            process.Refresh();
            var initialWS = process.WorkingSet64;
            var initialPB = process.PrivateMemorySize64;

            Console.WriteLine($"Create array of {N} interpreters.");
            DyalogInterpreter[] interpreterArray = new DyalogInterpreter[N];
            CodeFile[]          aplcArray        = new CodeFile[N];
            string[]            codeFiles        = usecodefile ? new[] { codefile } : null;

            Console.WriteLine($"Interpreter, WS, PB, ElapsedMS");
            Console.WriteLine($" -1,{initialWS,15},{initialPB,15},0");
            for (var i = 0; i < N; i++)
            {
                stopwatch.Restart();
                var interpreter = CreateInterpreter(codeFiles);
                var aplc        = new CodeFile(interpreter);
                interpreterArray[i] = interpreter;
                aplcArray[i]        = aplc;
                if (!usecodefile)
                {
                    aplc.LoadWS(codefile);
                }
                stopwatch.Stop();
                process.Refresh();
                Console.WriteLine($"{i,3},{process.WorkingSet64,15},{process.PrivateMemorySize64,15}, {stopwatch.ElapsedMilliseconds}");
            }

            // execute function in each interpreter sequentially
            Console.WriteLine($"Execute different function trees in each interpreter.");
            Console.WriteLine($"Interpreter, WS, PB, ElapsedMS");
            for (var i = 0; i < N; i++)
            {
                var letter = alphabet.Substring(i, 1);
                stopwatch.Restart();
                aplcArray[i].Execute($"{i} #.A {i}");
                //aplcArray[i].Execute($"+/+/¨#.Cache{letter}Data");
                //aplcArray[i].Execute($"#.Cache{letter}LookUp 1");
                //aplcArray[i].Execute($"#.Cache{letter}LookUp 1");
                //aplcArray[i].Execute($"+/+/¨#.Cache{letter}Data");
                stopwatch.Stop();
                process.Refresh();
                Console.WriteLine($"{i,3},{process.WorkingSet64,15},{process.PrivateMemorySize64,15}, {stopwatch.ElapsedMilliseconds}");
            }
            // check time spent and memory
            process.Refresh();
            var finalWS            = process.WorkingSet64;
            var finalPB            = process.PrivateMemorySize64;
            var deltaWS_FinalTotal = finalWS - initialWS;
            var deltaPB_FinalTotal = finalPB - initialPB;

            Console.WriteLine($"Delta WS:{deltaWS_FinalTotal}; PB:{deltaPB_FinalTotal}");
            try {
                for (var i = 0; i < N; i++)
                {
                    aplcArray[i].Dispose();
                    interpreterArray[i].Unload();
                }
            } catch (Exception) { }
        }