Example #1
0
    static void TestCancellation(Communicator comm)
    {
        int datum         = comm.Rank;
        int expectedDatum = (comm.Rank + comm.Size - 1) % comm.Size;

        int[]    intArrayRecvBuffer = new int[expectedDatum + 1];
        string[] strArrayRecvBuffer = new string[expectedDatum + 1];

        int[]    intArraySendBuffer = new int[comm.Rank + 1];
        string[] strArraySendBuffer = new string[comm.Rank + 1];
        for (int i = 0; i <= comm.Rank; ++i)
        {
            intArraySendBuffer[i] = i;
            strArraySendBuffer[i] = i.ToString();
        }

        // Test cancellation of receive requests
        Request[] requests = new Request[4];
        requests[0] = comm.ImmediateReceive <int>(Communicator.anySource, 0);
        requests[1] = comm.ImmediateReceive <string>(Communicator.anySource, 1);
        requests[2] = comm.ImmediateReceive(Communicator.anySource, 2, intArrayRecvBuffer);
        requests[3] = comm.ImmediateReceive(Communicator.anySource, 3, strArrayRecvBuffer);

        // Cancel all of these requests.
        requests[0].Cancel();
        requests[1].Cancel();
        requests[2].Cancel();
        requests[3].Cancel();

        // Check that the requests were actually cancelled
        for (int i = 0; i < 4; ++i)
        {
            if (!requests[0].Wait().Cancelled)
            {
                System.Console.Error.WriteLine("error: cancelled receive request "
                                               + i.ToString() + " not marked as cancelled");
                comm.Abort(1);
            }
        }

        comm.Barrier();
    }
Example #2
0
    static void TestCancellation(Communicator comm)
    {
        int datum = comm.Rank;
        int expectedDatum = (comm.Rank + comm.Size - 1) % comm.Size;
        int[] intArrayRecvBuffer = new int[expectedDatum + 1];
        string[] strArrayRecvBuffer = new string[expectedDatum + 1];

        int[] intArraySendBuffer = new int[comm.Rank + 1];
        string[] strArraySendBuffer = new string[comm.Rank + 1];
        for (int i = 0; i <= comm.Rank; ++i)
        {
            intArraySendBuffer[i] = i;
            strArraySendBuffer[i] = i.ToString();
        }

        // Test cancellation of receive requests
        Request[] requests = new Request[4];
        requests[0] = comm.ImmediateReceive<int>(Communicator.anySource, 0);
        requests[1] = comm.ImmediateReceive<string>(Communicator.anySource, 1);
        requests[2] = comm.ImmediateReceive(Communicator.anySource, 2, intArrayRecvBuffer);
        requests[3] = comm.ImmediateReceive(Communicator.anySource, 3, strArrayRecvBuffer);

        // Cancel all of these requests.
        requests[0].Cancel();
        requests[1].Cancel();
        requests[2].Cancel();
        requests[3].Cancel();

        // Check that the requests were actually cancelled
        for (int i = 0; i < 4; ++i)
        {
            if (!requests[0].Wait().Cancelled)
            {
                System.Console.Error.WriteLine("error: cancelled receive request " 
                    + i.ToString() + " not marked as cancelled");
                comm.Abort(1);
            }
        }

        comm.Barrier();
    }