本文整理汇总了C#中Communicator.Send方法的典型用法代码示例。如果您正苦于以下问题:C# Communicator.Send方法的具体用法?C# Communicator.Send怎么用?C# Communicator.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Communicator
的用法示例。
在下文中一共展示了Communicator.Send方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestWrite
public void TestWrite()
{
using (MemoryStream stream = new MemoryStream())
{
Communicator communicator = new Communicator(
new StreamSimpleCommunicator<object>(stream, null));
foreach (object message in
new object[] { new A { UIntValue = 1 }, new A { UIntValue = 2 } })
{
communicator.Send(message);
}
AssertExtensions.AreEqual(
new byte[] { 0x02, 0x08, 0x01, 0x02, 0x08, 0x02 },
stream.ToArray());
}
}
示例2: Main
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);
//.........这里部分代码省略.........
示例3: 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));
//.........这里部分代码省略.........