예제 #1
0
        private static void MatrixMulShared(ArrayView <float> a, ArrayView <float> b, ArrayView <float> c, int N)
        {
            int index = Grid.GlobalIndex.X;

            if (index >= c.Length)
            {
                return;
            }

            int gx = Grid.GlobalIndex.X;
            int gy = Grid.GlobalIndex.Y;
            int lx = Group.IdxX;
            int ly = Group.IdxY;

            float sum = 0;

            var sa = SharedMemory.Allocate2D <float>(groupSize, groupSize);
            var sb = SharedMemory.Allocate2D <float>(groupSize, groupSize);

            for (int k = 0; k < N; k += groupSize)
            {
                sa[lx, ly] = a[gy * N + lx + k];
                sb[lx, ly] = b[(ly + k) * N + gx];
                Group.Barrier();
                for (int r = 0; r < groupSize; r++)
                {
                    sum += sa[r, ly] * sb[lx, r];
                }
                Group.Barrier();
            }
            c[gy * N + gx] = sum;
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        public void Dispose()
        {
            try
            {
                if (sm != null)
                {
                    sm.Dispose();
                    sm = null;
                }
            }
            catch
            {}

            try
            {
                ResponseCrate rc = null;
                foreach (var el in df.ToList())
                {
                    if (df.TryRemove(el.Key, out rc))
                    {
                        if (rc.mre != null)
                        {
                            rc.IsRespOk = false;
                            rc.mre.Set();
                            rc.mre.Dispose();
                            rc.mre = null;
                        }
                    }
                }
            }
            catch
            {
            }
        }
예제 #3
0
        public void NestedVectorTest()
        {
            var name = Guid.NewGuid().ToString();

            using (var memory = SharedMemory.Create(name, 1024 * 1024))
                using (var vv = Factory.Make <IVector <IVector <int> > >(memory))
                {
                    const int N = 5;
                    const int x = 123;

                    for (int i = 0; i < N; ++i)
                    {
                        using (var v = Factory.Make <IVector <int> >(memory))
                        {
                            v.Resize(N, x);
                            Assert.AreEqual(N, v.Count);

                            vv.Add(v);
                        }
                    }

                    Assert.AreEqual(N, vv.Count);
                    Assert.AreEqual(N * N * x, vv.Sum((v) => { using (v) return(v.Sum()); }));
                }
        }
예제 #4
0
        public void RunTest()
        {
            const int     id0       = 100;
            const int     blockSize = 16;
            SharedMemory  memory    = new SharedMemory(Channel.FromHash("Test"));
            List <IntPtr> blocks    = new List <IntPtr>();

            //Create
            for (int i = 0; i < 200; ++i)
            {
                blocks.Add(memory.Allocate(id0 + i, 4 * blockSize, 4).Pointer);
            }

            //Write
            for (int i = 0; i < 200; ++i)
            {
                for (int j = 0; j < blockSize; ++j)
                {
                    Assert.AreEqual(0, Marshal.ReadInt32(blocks[i], j * 4));
                    Marshal.WriteInt32(blocks[i], j * 4, i + j);
                }
            }

            //Read
            for (int i = 0; i < 200; ++i)
            {
                for (int j = 0; j < blockSize; ++j)
                {
                    Assert.AreEqual(i + j, Marshal.ReadInt32(blocks[i], j * 4));
                }
            }
        }
        public ContentResult DownloadFile(string idBulkCatalog)
        {
            var    oneBulkCatalog = _bulkLoadCatalogBusiness.GetOne(new Guid(idBulkCatalog));
            string returnValue    = string.Empty;
            int?   statusCode     = (int)HttpStatusCode.OK;

            foreach (var fileTemp in Request.Form.Files)
            {
                var fileName       = fileTemp.FileName;
                int indexSeparator = fileName.LastIndexOf(".", StringComparison.Ordinal);

                //validar extensión de archivo
                if (0 < indexSeparator)
                {
                    if (!CBulkLoad.Extention.Equals(fileName.Substring(indexSeparator + 1).ToUpper()))
                    {
                        returnValue = "Archivo no válido, extensión no válida";
                        statusCode  = (int)HttpStatusCode.NotAcceptable;
                        break;
                    }
                }
                else
                {
                    returnValue = "Archivo no válido, no hay extensión";
                    statusCode  = (int)HttpStatusCode.NotAcceptable;
                    break;
                }

                //validacion de contenido
                if (1 < fileTemp.Length)
                {
                    byte[] bufferDocument;
                    returnValue = BulkLoadUtil.ValidateContentBulkFile(fileTemp, oneBulkCatalog.Separator
                                                                       , oneBulkCatalog.ColumnNumber, out bufferDocument);

                    if (string.IsNullOrEmpty(returnValue))
                    {
                        SharedMemory.Set(CBulkLoad.CSessionFile, bufferDocument);

                        returnValue = "Archivo válido";
                        statusCode  = (int)HttpStatusCode.OK;
                        break;
                    }

                    statusCode = (int)HttpStatusCode.NotAcceptable;
                    break;
                }

                returnValue = "Error, Archivo Vacio";
                statusCode  = (int)HttpStatusCode.NotAcceptable;
            }

            var response = new ContentResult
            {
                Content    = returnValue,
                StatusCode = statusCode
            };

            return(response);
        }
        public unsafe static void RunLocal()
        {
            var         mem  = new SharedMemory(_channel.GetSubChannel("mem"));
            int *       ptr1 = (int *)mem.Allocate(_channel.GetSubChannel("A"), 4, 4).Pointer;
            int *       ptr2 = (int *)mem.Allocate(_channel.GetSubChannel("B"), 4, 4).Pointer;
            Func <bool> func = () => Volatile.Read(ref *ptr2) == 2;

            FastSpinUntil(() => Volatile.Read(ref *ptr2) == 1, 2000);

            for (int i = 0; i < 50; ++i)
            {
                Volatile.Write(ref *ptr1, 1);
                FastSpinUntil(func, 2000);
                Volatile.Write(ref *ptr2, 1);
            }

            var clock = Stopwatch.StartNew();

            for (int i = 0; i < 50; ++i)
            {
                Volatile.Write(ref *ptr1, 1);
                FastSpinUntil(func, 2000);
                Volatile.Write(ref *ptr2, 1);
            }

            var time = clock.ElapsedTicks / (float)TimeSpan.TicksPerMillisecond * 1000;

            Console.WriteLine("Average round-trip delay: {0} us", time / 50);
        }
예제 #7
0
 public Serializer(ISerializer <InputStream, OutputStream> serializer, BufferPool pool, SharedMemory inputMemory, uint minBlobSize = 0)
 {
     _pool        = pool;
     _inputMemory = inputMemory;
     _minBlobSize = minBlobSize;
     _serializer  = serializer;
 }
예제 #8
0
 static void Main(string[] args)
 {
     Console.Title = "HostB";
     Console.ReadLine();
     using (var sm = SharedMemory.Open("SM1"))
     {
         using (var r = sm.AsReader())
         {
             Console.WriteLine(r.ReadInt32());
             Console.WriteLine(r.ReadInt32());
             Console.WriteLine(r.ReadInt32());
             Console.WriteLine(r.ReadBytes(5).MakeString());
         }
     }
     Console.ReadLine();
     using (var sm2 = SharedMemory.Open("SM2"))
     {
         using (var r = sm2.AsReader(0L, 1L * 1024))
         {
             Console.WriteLine(r.ReadBytes((int)r.Size).MakeString());
         }
         Console.ReadLine();
         using (var r = sm2.AsReader(1L * 1024, 1L * 1024))
         {
             Console.WriteLine(r.ReadBytes((int)r.Size).MakeString());
         }
         Console.ReadLine();
         using (var r = sm2.AsReader(0L, 1L * 1024))
         {
             Console.WriteLine(r.ReadBytes((int)r.Size).MakeString());
         }
         Console.ReadLine();
     }
 }
예제 #9
0
        public void Initialize(Switch device, Horizon system, KSharedMemory sharedMemory, long timeSharedMemoryAddress, int timeSharedMemorySize)
        {
            SharedMemory.Initialize(device, sharedMemory, timeSharedMemoryAddress, timeSharedMemorySize);

            // Here we use system on purpose as device. System isn't initialized at this point.
            StandardUserSystemClock.CreateAutomaticCorrectionEvent(system);
        }
예제 #10
0
        public void SerializerTest()
        {
            using (var memory = SharedMemory.Create(Guid.NewGuid().ToString(), 4 * 1024 * 1024))
                using (var pool = new BufferPool(memory))
                {
                    foreach (var protocol in new global::Bond.ProtocolType[] { global::Bond.ProtocolType.COMPACT_PROTOCOL, global::Bond.ProtocolType.FAST_PROTOCOL, global::Bond.ProtocolType.SIMPLE_PROTOCOL })
                    {
                        foreach (var marshal in new bool[] { true, false })
                        {
                            var serializer = new Serializer(protocol, marshal, pool, memory);

                            Assert.AreEqual(protocol, serializer.ProtocolType);
                            Assert.AreEqual(marshal, serializer.IsMarshaled);

                            var        s1 = MakeRandomStruct();
                            TestStruct s2;

                            using (var buffer = serializer.Serialize(s1))
                            {
                                s2 = serializer.Deserialize <TestStruct>(buffer);
                            }

                            // Bond.Comparer.Equal does not properly work with Bonded<T> fields.
                            Assert.IsTrue(global::Bond.Comparer.Equal(s1.FieldBonded.Deserialize(), s2.FieldBonded.Deserialize()));
                            s1.FieldBonded = s2.FieldBonded = global::Bond.Bonded <ValueStruct> .Empty;

                            Assert.IsTrue(global::Bond.Comparer.Equal(s1, s2));
                        }
                    }
                }
        }
예제 #11
0
        private static ArrayView <T> InclusiveScanImplementation <
            T,
            TScanOperation,
            TImpl>(
            T value)
            where T : unmanaged
            where TScanOperation : struct, IScanReduceOperation <T>
            where TImpl : struct, IILFunctionImplementation
        {
            TImpl impl = default;

            // Load values into shared memory
            var sharedMemory = SharedMemory.Allocate <T>(impl.MaxNumThreads);

            Debug.Assert(
                impl.ThreadDimension <= impl.MaxNumThreads,
                "Invalid group/warp size");
            sharedMemory[impl.ThreadIndex] = value;
            impl.Barrier();

            // First thread performs all operations
            if (impl.IsFirstThread)
            {
                TScanOperation scanOperation = default;
                for (int i = 1; i < impl.ThreadDimension; ++i)
                {
                    sharedMemory[i] = scanOperation.Apply(
                        sharedMemory[i - 1],
                        sharedMemory[i]);
                }
            }
            impl.Barrier();

            return(sharedMemory);
        }
예제 #12
0
        static void Main(string[] args)
        {
            int          cnt          = 0;
            SharedMemory sharedMemory = new SharedMemory();

            while (!Console.KeyAvailable)
            {
                var read = sharedMemory.ReadStringM2D();
                if (read.Length > 0)
                {
                    var baseObject = JsonSerializer.Deserialize <Communication.Base>(read);
                    if (baseObject.type == "Hello")
                    {
                        var hello = JsonSerializer.Deserialize <Communication.Hello>(baseObject.json);
                        Console.WriteLine("[" + baseObject.type + "]" + hello.msg);
                    }
                }

                sharedMemory.WriteStringD2M(JsonSerializer.Serialize(new Communication.Base
                {
                    type = "Hello",
                    json = JsonSerializer.Serialize(new Communication.Hello
                    {
                        msg = "Hello from C# mock"
                    })
                }));
                cnt++;
                Thread.Sleep(500);
            }
        }
예제 #13
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                producer = new SharedMemory("noname1", 255);
                consumer = new SharedMemory("noname2", 255);
            }
            else
            {
                producer = new SharedMemory("noname2", 255);
                consumer = new SharedMemory("noname1", 255);
            }

            consumer.ReceiveHandler += new ReceivedEventHandler <byte[]>(Program.HandleConsumerReceiveEvent);

            //Console.WriteLine("Press return to start ");
            //Console.ReadLine();
            if (args.Length > 0)
            {
                Console.WriteLine("Sending PING");
                producer.Write(ASCIIEncoding.ASCII.GetBytes("PING: " + DateTime.Now.ToString()));
            }

            Console.WriteLine("Press return to exit ");
            Console.ReadLine();
            consumer.Close();
            producer.Close();
        }
예제 #14
0
        internal unsafe SharedMemory RentNative(int bucketSize)
        {
            var bucketIndex = SelectBucketIndex(bucketSize);

            BufferRef.EnsureBucketIndexInRange(bucketIndex);

            // We must init the buffer header before allocating.
            // We know from inside BRA.Allocate txn the value or BufferRef
            // before committing. For new we must init the header,
            // for one from the free list we must assert the buffer is disposed
            // and not owned (it may be in Releasing state though).

            var br = _bra.Allocate((byte)bucketIndex, out _, _buckets);

            var db = _buckets.DangerousGet(br);

            var sm = SharedMemory.Create(db, br, this);

            Debug.Assert(sm.IsDisposed);
            Debug.Assert(Unsafe.Read <uint>(sm.HeaderPointer) == (HeaderFlags.Releasing | HeaderFlags.IsDisposed));

            sm.FromReleasingDisposedToOwned();

            Debug.Assert(!sm.IsDisposed);
            Debug.Assert(sm.ReferenceCount == 0);
            Debug.Assert(Unsafe.Read <uint>(sm.HeaderPointer) == HeaderFlags.IsOwned);

            return(sm);
        }
        /// <summary>クライアント生成 - ReadWriteスレッド関数</summary>
        private void ReadWriteSharedMemory()
        {
            // 共有メモリ(サーバ)
            SharedMemory sm = null;

            // スレッドID
            int managedThreadId = Thread.CurrentThread.ManagedThreadId;

            try
            {
                // 共有メモリを生成(256バイト)
                sm = new SharedMemory("my-sm", 256, "my-mtx");

                // マップ
                sm.Map(0, 0);
                // ロック
                sm.Lock();

                // 受信(バイト → int)
                byte[] rcvByte = null;
                sm.GetMemory(out rcvByte, 0);
                //int i = BitConverter.ToInt32(rcvByte, 0);
                short i = BitConverter.ToInt16(rcvByte, 0);

                // 受信メッセージを表示
                this.SetResult_Client(
                    string.Format("({0})受信:{1}", managedThreadId, i.ToString()));

                // 送信(int → バイト)
                byte[] sndByte = null;

                // 共有メモリを初期化
                sm.SetMemory(this.InitBuff(256), 256);

                // (++i)を送信
                sndByte = BitConverter.GetBytes(++i);
                sm.SetMemory(sndByte, sndByte.Length);
                //sm.SetMemory(sndByte, sndByte.Length);

                // 送信メッセージを表示
                this.SetResult_Client(
                    string.Format("({0})送信:{1}", managedThreadId, i.ToString()));
            }
            catch (Exception ex)
            {
                // エラーを表示
                this.SetResult_Client(
                    string.Format("({0})エラー:{1}", managedThreadId, ex.ToString()));
            }
            finally
            {
                if (sm != null)
                {
                    // 共有メモリをクローズ
                    // アンロック&マネージ・アンマネージリソースの解放
                    sm.Close();// ←コメントアウトするとGC任せになるが、ミューテックスの解放が遅れる!
                }
            }
        }
        public IActionResult LoadFile(string idBulkCatalog)
        {
            SharedMemory.Remove(CBulkLoad.CSessionFile);

            ViewData[CBulkLoad.SelectCatalog] = _bulkLoadCatalogBusiness.GetOne(new Guid(idBulkCatalog));

            return(View());
        }
예제 #17
0
        void Profile_ProfileStopped(object sender, EventArgs e)
        {
            _textureMemory.Close();
            _textureMemory.Dispose();
            _textureMemory = null;

            IsRunning = false;
        }
예제 #18
0
        internal override void InitData()
        {
            _sharedMemory = new SharedMemory("FalconSharedMemoryArea");
            _sharedMemory.Open();

            _sharedMemory2 = new SharedMemory("FalconSharedMemoryArea2");
            _sharedMemory2.Open();
        }
예제 #19
0
        public void SetStandardSteadyClockRtcOffset(ITickSource tickSource, TimeSpanType rtcOffset)
        {
            StandardSteadyClock.SetSetupValue(rtcOffset);

            TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(tickSource);

            SharedMemory.SetSteadyClockRawTimePoint(tickSource, currentTimePoint);
        }
예제 #20
0
 public GameInstanceData GetGameData(int pid)
 {
     if (pid == 0)
     {
         return(new GameInstanceData(null));
     }
     return(new GameInstanceData(SharedMemory.GetPageByPID(pid)));
 }
예제 #21
0
        public void SetStandardSteadyClockRtcOffset(KThread thread, TimeSpanType rtcOffset)
        {
            StandardSteadyClock.SetSetupValue(rtcOffset);

            TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(thread);

            SharedMemory.SetSteadyClockRawTimePoint(thread, currentTimePoint);
        }
예제 #22
0
            /// <summary>
            /// アイコン一覧の取得
            /// </summary>
            public static void ReadIconList()
            {
                int    dwBufferSize  = 1024;
                IntPtr lpLocalBuffer = Marshal.AllocHGlobal(dwBufferSize);

                lock (iconInfoList)
                {
                    iconInfoList.Clear();
                    IntPtr hDesktopListView = GetFindDesktopListViewWnd.getDesktopListViewAddress();
                    IntPtr baseAddress      = SharedMemory.getRemoteBufferAddress();
                    int    IconCount        = ListView_GetItemCount(hDesktopListView);

                    try
                    {
                        for (int IconNo = 0; IconNo < IconCount; IconNo++)
                        {
                            IntPtr ipIconNo = (IntPtr)IconNo;
                            // テキスト取得
                            LV_ITEM LocalItem = new LV_ITEM();
                            LocalItem.mask       = LVIF_TEXT;
                            LocalItem.iItem      = 0;
                            LocalItem.pszText    = (IntPtr)(baseAddress.ToInt32() + Marshal.SizeOf(typeof(LV_ITEM)));
                            LocalItem.cchTextMax = 256;
                            SharedMemory.ProcessWrite(baseAddress, ref LocalItem, Marshal.SizeOf(typeof(LV_ITEM)));
                            int Len = SendMessage(hDesktopListView, LVM_GETITEMTEXT, ipIconNo, baseAddress);
                            // char[] LocalText = new char[256];
                            // System.Runtime.InteropServices.Marshal.StructureToPtr(LocalText, lpLocalBuffer, true);
                            SharedMemory.ProcessRead(baseAddress, lpLocalBuffer, dwBufferSize);
                            string iconText = Marshal.PtrToStringAnsi((IntPtr)(lpLocalBuffer.ToInt32() + Marshal.SizeOf(typeof(LV_ITEM))));

                            // アイコン矩形取得&チェック
                            RECT LocalRect = new RECT();
                            LocalRect.left = LVIR_ICON;
                            SharedMemory.ProcessWrite(baseAddress, ref LocalRect, Marshal.SizeOf(typeof(RECT)));
                            SendMessage(hDesktopListView, LVM_GETITEMRECT, (IntPtr)IconNo, baseAddress);
                            Marshal.StructureToPtr(LocalRect, lpLocalBuffer, true);
                            SharedMemory.ProcessRead(baseAddress, lpLocalBuffer, Marshal.SizeOf(typeof(RECT)));
                            LocalRect = (RECT)Marshal.PtrToStructure(lpLocalBuffer, typeof(RECT));
                            setIconList(LocalRect, iconText);
                            // テキスト矩形取得&チェック
                            LocalRect.left = LVIR_LABEL;
                            SharedMemory.ProcessWrite(baseAddress, ref LocalRect, Marshal.SizeOf(typeof(RECT)));
                            SendMessage(hDesktopListView, LVM_GETITEMRECT, (IntPtr)IconNo, baseAddress);
                            Marshal.StructureToPtr(LocalRect, lpLocalBuffer, true);
                            SharedMemory.ProcessRead(baseAddress, lpLocalBuffer, Marshal.SizeOf(typeof(RECT)));
                            LocalRect = (RECT)Marshal.PtrToStructure(lpLocalBuffer, typeof(RECT));
                            setIconList(LocalRect, iconText);
                        }
                    }
                    finally
                    {
                        if (lpLocalBuffer != IntPtr.Zero)
                        {
                            Marshal.FreeHGlobal(lpLocalBuffer);
                        }
                    }
                }
            }
예제 #23
0
        private static void IlGpuKernelConstants(
            ArrayView2D <Real> mSquaredDistances,
            ArrayView <Real> mCoordinates,
            SpecializedValue <int> c,
            int n)
        {
            // Same as CudaKernelOptimised2, but the number of coordinates is given as a meta-constant.
            // Also, we write the results as float2.

            var shared       = SharedMemory.GetDynamic <Real>();
            var coordinatesI = shared.GetSubView(0, c * Group.DimX);
            var coordinatesJ = shared.GetSubView(c * Group.DimX);

            var bI = Grid.IdxY * Group.DimX;
            var bJ = Grid.IdxX * Group.DimX;

            for (int k = 0; k != c; ++k)
            {
                if (bI + Group.IdxX < n)
                {
                    coordinatesI[k * Group.DimX + Group.IdxX] = mCoordinates[k * n + bI + Group.IdxX];
                }

                if (bJ + Group.IdxX < n)
                {
                    coordinatesJ[k * Group.DimX + Group.IdxX] = mCoordinates[k * n + bJ + Group.IdxX];
                }
            }

            Group.Barrier();

            var line = Group.IdxX / (Group.DimX / 2);
            var tid  = Group.IdxX % (Group.DimX / 2);

            if (bJ + tid * 2 < n)
            {
                var coordinatesJ2 = coordinatesJ.Cast <IlReal2>();

                for (int i = line; i < Group.DimX & bI + i < n; i += 2)
                {
                    var dist = default(IlReal2);

                    for (int k = 0; k != c; ++k)
                    {
                        var coord1 = coordinatesI[k * Group.DimX + i];
                        var coord2 = coordinatesJ2[(k * Group.DimX / 2) + tid];
                        var diff   = new IlReal2(coord1 - coord2.X, coord1 - coord2.Y);

                        dist += diff * diff;
                    }

                    var dst = mSquaredDistances.Cast <IlReal2>();
                    dst[bJ / 2 + tid, bI + i] = dist;
                }
            }
        }
예제 #24
0
        /// <summary>サーバ起動 - pollingスレッド関数</summary>
        private void PollingSharedMemory(object o)
        {
            // 共有メモリ(サーバ)
            SharedMemory sm = null;

            // スレッドID
            int managedThreadId = Thread.CurrentThread.ManagedThreadId;

            try
            {
                // 共有メモリを生成
                sm = new SharedMemory("my-sm", 256, "my-mtx");

                // マップ
                sm.Map(0, 0);

                // Polling開始を表示
                this.SetResult_Svr(
                    string.Format("Polling開始! - ThreadId:{0}", managedThreadId));

                // Polling処理

                while (!End)
                {
                    byte[] byt = null;
                    sm.GetMemory(out byt, 0);
                    //int msg = BitConverter.ToInt32(byt, 0);
                    short msg = BitConverter.ToInt16(byt, 0);

                    // 受信メッセージを表示
                    this.SetResult_Svr(
                        string.Format("({0})受信:{1}", managedThreadId, msg.ToString()));

                    Thread.Sleep(0); // Polling間隔
                }

                // Polling停止を表示
                this.SetResult_Svr(
                    string.Format("Polling停止! - ThreadId:{0}", managedThreadId));
            }
            catch (Exception ex)
            {
                // エラーを表示
                this.SetResult_Svr(
                    string.Format("({0})エラー:{1}", managedThreadId, ex.ToString()));
            }
            finally
            {
                if (sm != null)
                {
                    // 共有メモリをクローズ
                    // アンロック&マネージ・アンマネージリソースの解放
                    sm.Close();// ←コメントアウトするとGC任せになるが、ミューテックスの解放が遅れる!
                }
            }
        }
예제 #25
0
        public void SetupStandardSteadyClock(KThread thread, UInt128 clockSourceId, TimeSpanType setupValue, TimeSpanType internalOffset, TimeSpanType testOffset, bool isRtcResetDetected)
        {
            SetupInternalStandardSteadyClock(clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);

            TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(thread);

            SharedMemory.SetupStandardSteadyClock(thread, clockSourceId, currentTimePoint);

            // TODO: propagate IPC late binding of "time:s" and "time:p"
        }
예제 #26
0
        internal override void CloseData()
        {
            _sharedMemory.Close();
            _sharedMemory.Dispose();
            _sharedMemory = null;

            _sharedMemory2.Close();
            _sharedMemory2.Dispose();
            _sharedMemory2 = null;
        }
예제 #27
0
        public void Initalize()
        {
            var testHelper = new TestHelper();

            _config              = testHelper.Configuration;
            _sharedMemory        = new SharedMemory();
            _weatherReport       = testHelper.weatherReport();
            weatherReportService = new WeatherReportService(_sharedMemory, _config);
            SaveCityReportTest();
        }
예제 #28
0
        /// <summary>
        /// SharmIpc constructor
        /// </summary>
        /// <param name="uniqueHandlerName">Must be unique in OS scope (can be PID [ID of the process] + other identifications)</param>
        /// <param name="remoteCallHandler">Callback routine for the remote partner requests. AsyncAnswerOnRemoteCall must be used for answer</param>
        /// <param name="bufferCapacity">bigger buffer sends larger datablocks faster. Default value is 50000</param>
        /// <param name="maxQueueSizeInBytes">If remote partner is temporary not available, messages are accumulated in the sending buffer. This value sets the upper threshold of the buffer in bytes.</param>
        public SharmIpc(string uniqueHandlerName, Action <ulong, byte[]> remoteCallHandler, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000)
        {
            if (remoteCallHandler == null)
            {
                throw new Exception("tiesky.com.SharmIpc: remoteCallHandler can't be null");
            }

            this.AsyncRemoteCallHandler = remoteCallHandler;
            sm = new SharedMemory(uniqueHandlerName, this.InternalDataArrived, bufferCapacity, maxQueueSizeInBytes);
        }
예제 #29
0
        private static void IlGpuKernelFloat2(
            ArrayView2D <Real> mSquaredDistances,
            ArrayView <Real> mCoordinates,
            int c,
            int n)
        {
            // Same as KernelSharedMemory, but one thread does two element in one by using float2 reads.

            var shared       = SharedMemory.GetDynamic <Real>();
            var coordinatesI = shared.GetSubView(0, c * Group.DimX);
            var coordinatesJ = shared.GetSubView(c * Group.DimX);

            var bI = Grid.IdxY * Group.DimX;
            var bJ = Grid.IdxX * Group.DimX;

            for (int k = 0; k != c; ++k)
            {
                if (bI + Group.IdxX < n)
                {
                    coordinatesI[k * Group.DimX + Group.IdxX] = mCoordinates[k * n + bI + Group.IdxX];
                }

                if (bJ + Group.IdxX < n)
                {
                    coordinatesJ[k * Group.DimX + Group.IdxX] = mCoordinates[k * n + bJ + Group.IdxX];
                }
            }

            Group.Barrier();

            var line = Group.IdxX / (Group.DimX / 2);
            var tid  = Group.IdxX % (Group.DimX / 2);

            if (bJ + tid * 2 < n)
            {
                var coordinatesJ2 = coordinatesJ.Cast <IlReal2>();

                for (int i = line; i < Group.DimX && bI + i < n; i += 2)
                {
                    var dist = default(IlReal2);

                    for (int k = 0; k != c; ++k)
                    {
                        var coord1 = coordinatesI[k * Group.DimX + i];
                        var coord2 = coordinatesJ2[(k * Group.DimX / 2) + tid];
                        var diff   = new IlReal2(coord1 - coord2.X, coord1 - coord2.Y);

                        dist += diff * diff;
                    }

                    mSquaredDistances[bJ + 2 * tid + 0, bI + i] = dist.X;
                    mSquaredDistances[bJ + 2 * tid + 1, bI + i] = dist.Y;
                }
            }
        }
예제 #30
0
        static void Main(string[] args)
        {
            Console.Title = "HostA";
            SharedMemory sm = SharedMemory.Create("SM1", 1024);

            using (var w = sm.AsWriter())
            {
                w.Write(1);
                w.Write(2);
                w.Write(3);
                w.Write(new byte[5] {
                    0x4, 0x5, 0x6, 0x7, 0x8
                });
            }
            Console.WriteLine("Values written to shared memory = {0}", sm.Name);
            Console.ReadLine();
            SharedMemory sm2 = SharedMemory.Create("SM2", 2L * 1024);

            using (var w = sm2.AsWriter(offset: 0L, size: 1L * 1024))
            {
                var buffer1 = new byte[1 * 1024];
                for (int i = 0; i < buffer1.Length; i += 2)
                {
                    buffer1[i]     = 0xA;
                    buffer1[i + 1] = 0xB;
                }
                w.Write(buffer1);
                Console.WriteLine("Values written to shared memory = {0} offset = {1} size = {2}", w.Source.Name, w.Offset, w.Size);
            }
            Console.ReadLine();
            using (var w = sm2.AsWriter(offset: 1L * 1024, size: 1L * 1024))
            {
                var buffer2 = new byte[1 * 1024];
                for (int i = 0; i < buffer2.Length; i += 2)
                {
                    buffer2[i]     = 0xD;
                    buffer2[i + 1] = 0xE;
                }
                w.Write(buffer2);
                Console.WriteLine("Values written to shared memory = {0} offset = {1} size = {2}", w.Source.Name, w.Offset, w.Size);
            }
            Console.ReadLine();
            using (var w = sm2.AsWriter(offset: 0L, size: 1L * 1024))
            {
                var buffer1 = new byte[1 * 1024];
                for (int i = 0; i < buffer1.Length; i += 2)
                {
                    buffer1[i]     = 0xC;
                    buffer1[i + 1] = 0xF;
                }
                w.Write(buffer1);
                Console.WriteLine("Values written to shared memory = {0} offset = {1} size = {2}", w.Source.Name, w.Offset, w.Size);
            }
            Console.ReadLine();
        }
예제 #31
0
        public ConsoleHandler()
        {
            // Create objects for shared memory.
            _consoleParams = new SharedMemory<ConsoleParams>();
            _consoleScreenInfo = new SharedMemory<CONSOLE_SCREEN_BUFFER_INFO>();
            _consoleCursorInfo = new SharedMemory<CONSOLE_CURSOR_INFO>();
            _consoleBufferInfo = new SharedMemory<ConsoleBufferInfo>();
            _consoleBuffer = new SharedMemory<CHAR_INFO>();
            _consoleCopyInfo = new SharedMemory<ConsoleCopyInfo>();
            _consolePasteInfo = new SharedMemory<UIntPtr>();
            _consoleMouseEvent = new SharedMemory<MOUSE_EVENT_RECORD>();
            _consoleNewSizeInfo = new SharedMemory<ConsoleSizeInfo>();
            _consoleNewScrollPos = new SharedMemory<SIZE>();

            _consoleVisible = false;
        }
        /// <summary>
        /// Set up ETS2 telemetry provider.
        /// Connects to shared memory map, sets up timebase.
        /// </summary>
        /// <param name="map">Memory Map location</param>
        /// <param name="interval">Timebase interval</param>
        private void Setup(string map, int interval)
        {
            Map = map;
            UpdateInterval = interval;

            SharedMemory = new SharedMemory();
            SharedMemory.Connect(map);

            if (!SharedMemory.Hooked)
            {
                Error = SharedMemory.HookException;
                return;
            }

            _updateTimer = new Timer { Interval = interval };
            _updateTimer.Elapsed += _updateTimer_Elapsed;
            _updateTimer.Start();
        }