Pembicaraan Wikipedia:Menyunting sebuah halaman: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
k salin pembicaraan |
|||
Baris 1:
using System;
using Alchemi.Parallel;
using Environment = Alchemi.Parallel.Environment;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int size, rank, i, j,s,p,r;
object data;
DateTime tmenow = DateTime.Now;
int mls = tmenow.Millisecond;
Random rndnumber = new Random(mls);
MPI mpi = Alchemi.Parallel.Environment.GetInstance().GetMPI;
mpi.Init();
mpi.Comm_Size(out size);
mpi.Comm_Rank(out rank);
MPI_Comm comm = new MPI_Comm("Andrew");
MPI_Status status = new MPI_Status();
int[] data1, data3,temp; int n = Int32.Parse(args[1]);
data1 = new int[n];
data3 = new int[n]; temp = new int[n];
// data1[1] = 13; data1[2] = 16; data1[3] = 14;
r = n % size;
if (rank == 0)
{
s = n / size;
int numWorkers = size - 1;
Console.WriteLine("dikasih kesiapa ???jumlah prosesor {0}= {1}={2}={3}", numWorkers,s,size,rank);
for (i = 0; i < n; i++)
data1[i] = rndnumber.Next(0, 999);/* kriim ke pekerja */
for (int d = 1; d <= numWorkers; d++)
{
for (i = d * s; i < (s * (d + 1)); i++)
{
mpi.Send(data1[i], d, 0, comm);
}
}
/* terima dari pekerja*/
Object offsetArray;
int dest;
Console.WriteLine("untuk dikerjakan proseor 0");
for (int yi = 0; yi < s; yi++)
{
//untuk id =0
data3[yi] = data1[yi];
Console.WriteLine("data ke {0} = {1}", yi, data3[yi]);
}
Console.WriteLine("============"); int tambah;
tambah = s;
for (int d = 1; d <= numWorkers; d++)
{
mpi.Recv(out offsetArray, d, 0, comm, status);
temp = (int[])offsetArray;
for (i = d * s; i < (s * (d + 1)); i++)
{
data3[i] = temp[i];
}
}
for (i = 0; i < n; i++)
{
Console.WriteLine("nilai awal {0}={1}", i, data3[i]);
}
}
else
{
Object payload;
int[] nilai; int nilaidata;
int[] nilai2; s = n / size;
nilai2 = new int[n]; nilai = new int[n];
/* receive data from master */
//terima dari master
int id; id = rank-1; //karena di prosesor 0 dikirim melalui id=0
//maka dibuat id=0
int tampung;
// nilai2 = new int[s + 2];
int kk = s;
Console.WriteLine("identifikasi pekerje = {0} ",rank);
// for (i = 0; i < s ; i++)
int d = rank;
for (i = d * s; i < (s * (d + 1)); i++)
{
mpi.Recv(out payload, 0, 0, comm, status);
tampung = (int)payload;
nilai2[i] = tampung;
Console.WriteLine("dikerjakan oleh pekerja {0} data {1}", i,nilai2[i]);
} //data ini harusnya disorting
//untuk percobaan dikirimkan
//id =1 . dari id kali s sampai id kalis+s
int ss = s; int ii = 0;
// kirim ke master
mpi.Send(nilai2, 0, 0, comm);
}
mpi.Finalise();
}
}
}
|