本文整理汇总了C#中Communicator.Barrier方法的典型用法代码示例。如果您正苦于以下问题:C# Communicator.Barrier方法的具体用法?C# Communicator.Barrier怎么用?C# Communicator.Barrier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Communicator
的用法示例。
在下文中一共展示了Communicator.Barrier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCancellation
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();
}
示例2: MPIMatrixMultiple
static void MPIMatrixMultiple(Communicator comm, string groupName)
{
var fileOffset = 2 * sizeof(int);
var matrixManager = new MatrixManager();
var matrixA = matrixManager.FileInitialization("A");
var matrixB = matrixManager.FileInitialization("B");
//var matrixA = new Matrix(11, 2);
//var matrixB = new Matrix(2, 4);
//Console.WriteLine("{0} {1} {2}", matrixA.Rows, matrixA.Columns, matrixB.Columns);
//matrixManager.SimpleInitialization(matrixA);
//matrixManager.SimpleInitialization(matrixB);
var rowsA = matrixA.Rows;
var columnA = matrixA.Columns;
var columnB = matrixB.Columns;
if (comm.Rank == 0)
{
int numberOfSlaves = comm.Size - 1;
var start = DateTime.Now;
int rowsPerSlave = rowsA / numberOfSlaves;
int remainingRows = rowsA % numberOfSlaves;
int offsetRow = 0;
var b = matrixB.Data;
((Intracommunicator)comm).Broadcast(ref b, 0);
for (var destination = 1; destination <= numberOfSlaves; destination++)
{
int rows = (destination <= remainingRows) ? rowsPerSlave + 1 : rowsPerSlave;
comm.Send(offsetRow, destination, (int)MessageType.FromMaster);
comm.Send(rows, destination, (int)MessageType.FromMaster);
var temp = new double[rows][];
for (var i = 0; i < rows; i++)
{
temp[i] = matrixA.Data[offsetRow];
}
comm.Send(temp, destination, (int)MessageType.FromMaster);
offsetRow = offsetRow + rows;
}
using (var fs = new FileStream(groupName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
{
byte[] buff = BitConverter.GetBytes(rowsA);
fs.Write(buff, 0, sizeof(int));
buff = BitConverter.GetBytes(columnB);
fs.Write(buff, 0, sizeof(int));
}
comm.Barrier();
DateTime end = DateTime.Now;
Console.WriteLine("Group name: {0} with size = {1}", groupName, comm.Size);
Console.Write("\n\n");
Console.Write(end - start);
}
else
{
double[][] b = null;
((Intracommunicator)comm).Broadcast<double[][]>(ref b, 0);
const int source = 0;
var offsetRow = comm.Receive<int>(source, (int)MessageType.FromMaster);
var rows = comm.Receive<int>(source, (int)MessageType.FromMaster);
var a = comm.Receive<double[][]>(source, (int)MessageType.FromMaster);
var c = new double[rows][];
for (var i = 0; i < rows; i++)
{
c[i] = new double[columnB];
}
//Console.WriteLine("{0} {1} {2}", columnB, rows, columnA);
using (var fs = new FileStream(groupName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
{
fs.Seek(sizeof (double)*offsetRow*columnB + fileOffset, SeekOrigin.Begin);
for (var k = 0; k < columnB; k++)
{
for (var i = 0; i < rows; i++)
{
c[i][k] = 0.0;
for (var j = 0; j < columnA; j++)
{
c[i][k] = c[i][k] + a[i][j] * b[j][k];
}
//Console.WriteLine("{0} {1:0.###} {2} {3} {4} {5}", comm.Rank, c[i][k], sizeof(double), offsetRow, i, k);
byte[] buff = BitConverter.GetBytes(c[i][k]);
fs.Write(buff, 0, sizeof(double));
//.........这里部分代码省略.........