Пример #1
0
    public virtual void broadcastCommsLocal()
    {
        if (communicator == null)
        {
            return;
        }

        communicator.Broadcast(beliefRepo.GetAllBeliefs());
    }
Пример #2
0
        protected void Enter()
        {
            var  req       = BuildCurrentMonitorMessage();
            long sentClock = Communicator.Broadcast(req, Tags.REQ_TAG);

            Requesting(sentClock);

            _syncEntryNumber++;
            Logger.LogCSEntry(Communicator.MyRank, _syncEntryNumber, Communicator.Clock);
        }
Пример #3
0
        protected void Signal(ConditionalVar condVar)
        {
            if (condVar.WaitingQueue.Any())
            {
                int destinationProc = condVar.WaitingQueue[0];
                condVar.WaitingQueue.RemoveAt(0);
                var msg = BuildCurrentMonitorMessage();
                Logger.LogPreSignal(Communicator.MyRank, destinationProc, _syncEntryNumber, Communicator.Clock);
                Communicator.Send(msg, destinationProc, Tags.WAKE_TAG);
                Communicator.Broadcast(msg, Tags.PRIORITY_REQ_TAG);
                PriorityRequesting();

                //add 1, it has to count as new entry
                _syncEntryNumber++;
                Logger.LogAfterSignalInCS(Communicator.MyRank, _syncEntryNumber, Communicator.Clock);
            }
        }
Пример #4
0
    static void Main(string[] args)
    {
        // Whether we should use the unsafe, Direct interface to MPI.
        // When false, use the normal MPI.NET interface.
        bool useDirectInterface = false;

        using (MPI.Environment env = new MPI.Environment(ref args))
        {
            if (args.Length > 0 && args[0] == "/direct")
            {
                useDirectInterface = true;
                System.Console.WriteLine("Using direct MPI interface.");
                System.Console.WriteLine("Bzzt.  Can't do that here.  Goodbye");
                return;
            }
            else
            {
                System.Console.WriteLine("Using MPI.NET interface.");
            }

            comm = MPI.Communicator.world;
            if (comm.Size != 2)
            {
                if (comm.Rank == 0)
                {
                    System.Console.WriteLine("Only two processes allowed.  Rerun with -np 2");
                }
                return;
            }
            else
            {
                self  = comm.Rank;
                other = (comm.Rank + 1) % 2;
            }

            System.Console.WriteLine(comm.Rank + ": " + MPI.Environment.ProcessorName);

            bwdata = new Data[nSamp];

            testLatency();
            testSyncTime();
            comm.Broadcast(ref latency, 0);

            if (self == 0)
            {
                System.Console.WriteLine("Latency: {0:F9}", latency);
                System.Console.WriteLine("Sync Time: {0:F9}", synctime);
                System.Console.WriteLine("Now starting main loop");
            }

            int    i, j, n, nq;
            int    inc = 1, len;
            int    start = 0, end = 1024 * 1024 * 1024;
            int    bufflen = start, bufalign = 16 * 1024;
            double tlast = latency;

            for (n = nq = 0, len = start; tlast < stopTime && len <= end; len += inc, nq++)
            {
                if (nq > 2 && (nq % 2 != 0))
                {
                    inc *= 2;
                }
                int ipert, pert;
                for (ipert = 0, pert = (inc > PERT + 1) ? -PERT : 0;
                     pert <= PERT;
                     ipert++, n++, pert += (inc > PERT + 1) ? PERT : PERT + 1)
                {
                    int nRepeat = bufflen == 0 ?
                                  latencyReps :
                                  (int)Math.Max((RUNTM / ((double)bufflen / (bufflen - inc + 1.0) * tlast)),
                                                TRIALS);
                    comm.Broadcast(ref nRepeat, 0);

                    bufflen = len + pert;
                    Tortoise[] sendBuffer = new Tortoise[bufflen]; // Align the data?  Some day.  Maybe.
                    Tortoise[] recvBuffer = new Tortoise[bufflen];
                    for (i = 0; i < bufflen; i++)
                    {
                        sendBuffer[i]          = new Tortoise();
                        sendBuffer[i].contents = 0;
                    }
                    if (self == 0)
                    {
                        System.Console.Write("{0,3:D}: {1,9:D} bytes {2,7:D} times ---> ", n, bufflen, nRepeat);
                    }

                    bwdata[n].t = 1e99;
                    double t1 = 0, t2 = 0;

                    for (i = 0; i < TRIALS; i++)
                    {
                        sync();
                        double t0 = when();
                        if (useDirectInterface)
                        {
                        }
                        else
                        {
                            for (j = 0; j < nRepeat; j++)
                            {
                                if (self == 0)
                                {
                                    comm.Send(sendBuffer, other, 142);
                                    comm.Receive(ref recvBuffer, other, 242);
                                }
                                else
                                {
                                    comm.Receive(ref recvBuffer, other, 142);
                                    comm.Send(sendBuffer, other, 242);
                                }
                            }
                        }
                        double t = (when() - t0) / (2.0 * nRepeat);
                        t2                += t * t;
                        t1                += t;
                        bwdata[n].t        = Math.Min(bwdata[n].t, t);
                        bwdata[n].variance = t2 / TRIALS - t1 / TRIALS * t1 / TRIALS;
                        tlast              = bwdata[n].t;
                        bwdata[n].bits     = bufflen * sizeof(byte) * 8;
                        bwdata[n].bps      = bwdata[n].bits / (bwdata[n].t * 1024 * 1024);
                        bwdata[n].repeat   = nRepeat;
                    }
                    if (self == 0)
                    {
                        System.Console.WriteLine("{0,9:F2} Mbps in {1:F9} sec", bwdata[n].bps, tlast);
                    }
                }
            }
        }
    }
Пример #5
0
    static void Main(string[] args)
    {
        // Whether we should use the unsafe, Direct interface to MPI.
        // When false, use the normal MPI.NET interface.
        bool useDirectInterface = false;

        using (MPI.Environment env = new MPI.Environment(ref args))
        {
            if (args.Length > 0 && args[0] == "/direct")
            {
                useDirectInterface = true;
                System.Console.WriteLine("Using direct MPI interface.");
                System.Console.WriteLine("Bzzt. Can't do that here.  Goodbye.");
                return;
            }
            else
                System.Console.WriteLine("Using MPI.NET interface.");

            comm = MPI.Communicator.world;
            if (comm.Size != 2)
            {
                if (comm.Rank == 0)
                    System.Console.WriteLine("Only two processes allowed.  Rerun with -np 2");
                return;
            }
            else
            {
                self = comm.Rank;
                other = (comm.Rank + 1) % 2;
            }

            System.Console.WriteLine(comm.Rank + ": " + MPI.Environment.ProcessorName);

            bwdata = new Data[nSamp];

            testLatency();
            testSyncTime();
            comm.Broadcast(ref latency, 0);

            if (self == 0)
            {
                System.Console.WriteLine("Latency: {0:F9}", latency);
                System.Console.WriteLine("Sync Time: {0:F9}", synctime);
                System.Console.WriteLine("Now starting main loop");
            }

            int i, j, n, nq;
            int inc = 1, len;
            int start = 0, end = 1024 * 1024 * 1024;
            int bufflen = start, bufalign = 16 * 1024;
            double tlast = latency;

            for (n = nq = 0, len = start; tlast < stopTime && len <= end; len += inc, nq++)
            {
                if (nq > 2 && (nq % 2 != 0)) inc *= 2;
                int ipert, pert;
                for (ipert = 0, pert = (inc > PERT + 1) ? -PERT : 0;
                     pert <= PERT;
                     ipert++, n++, pert += (inc > PERT + 1) ? PERT : PERT + 1)
                {
                    int nRepeat = bufflen == 0 ?
                                  latencyReps :
                                  (int)Math.Max((RUNTM / ((double)bufflen / (bufflen - inc + 1.0) * tlast)),
                                                TRIALS);
                    comm.Broadcast(ref nRepeat, 0);

                    bufflen = len + pert;
                    Hare[] sendBuffer = new Hare[bufflen]; // Align the data?  Some day.  Maybe.
                    Hare[] recvBuffer = new Hare[bufflen];
                    if (self == 0)
                        System.Console.Write("{0,3:D}: {1,9:D} bytes {2,7:D} times ---> ", n, bufflen, nRepeat);

                    bwdata[n].t = 1e99;
                    double t1 = 0, t2 = 0;
                    
                    for (i = 0; i < TRIALS; i++)
                    {
                        sync();
                        double t0 = when();
                        if (useDirectInterface)
                        {
                         
                        }
                        else
                        {
                            for (j = 0; j < nRepeat; j++)
                            {
                                if (self == 0)
                                {
                                    comm.Send(sendBuffer, other, 142);
                                    comm.Receive(ref recvBuffer, other, 242);
                                }
                                else
                                {
                                    comm.Receive(ref recvBuffer, other, 142);
                                    comm.Send(sendBuffer, other, 242);
                                }
                            }
                        }
                        double t = (when() - t0) / (2.0 * nRepeat);
                        t2 += t*t;
                        t1 += t;
                        bwdata[n].t = Math.Min(bwdata[n].t, t);
                        bwdata[n].variance = t2 / TRIALS - t1 / TRIALS * t1 / TRIALS;
                        tlast = bwdata[n].t;
                        bwdata[n].bits = bufflen * Marshal.SizeOf(typeof(Hare))*8;
                        bwdata[n].bps = bwdata[n].bits / (bwdata[n].t * 1024 * 1024);
                        bwdata[n].repeat = nRepeat;
                    }
                    if (self == 0)
                        System.Console.WriteLine("{0,9:F2} Mbps in {1:F9} sec", bwdata[n].bps, tlast);
                }
            }
        }
    }