, , , , , . .

 

 

!

 

:

:

 

 

 

?

StudentHelp, , MS Word. , , antiplagiat.ru, etxt.ru advego.ru. StudentHelp , Word .


:


:

: . : 12.06.2012. : 2011. : 10. antiplagiat.ru: < 30%

():



Գ,
-






: г






ʲ-08-1
..



. .






2011.


    򠠠2
    򠠠3
    3
    4
      ࠠ4
      5
      5
      򠠠6
    󠠠9
      䠠9
      䠠11
      16
    ꠠ16
    ˳ࠠ16




, ຠ . , . ++, (Message Passing Interface ) ᒺ.
Microsoft Visual Studio 2010
Win32 Console Aplocation
Microsoft HPC Pack 2008 SDK


---
( ). , .




: ( ), . , .
񠺠 .
( 1 )

A , b - . ( ):


, ( ) ,
. .
, .
- .
.
( 2 )

(2) ( ), . (1), (1) (2) , .

: . . . . : ( ). . . . : , . . .

, . ( ) .
, . , . , , . , , . . , , , . , . , , .
: . , . . : , ( , ), . .

. , , n ' , p, p <n, . , n ? n , , n / p .
, , :

.  . n / p, . (ni) / p, i, 0 ? i <n-1, . , ,  A. ʳ , , , (ni). , 2 (ni) ( aik / aii). , :

, . , :

ϳ

, :

. , ຠ ~ (2n / 3) / p3, , , .
. . 䳿 ( MPI_Allreduce MPI). logp 2,

, , ? - , ? - , w - .
볠 . :

. , , :

ϳ , , :

? .







. , , ᒺ, , .

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#define fileIn "D:/temp/tmp/ListNoZero.txt"
#define fileOut "D:/temp/tmp/result_noParallel.txt"
#define count 4096

bool WriteFile(float* a, int n, char* s); // .
bool ReadFile(float* a, int n, char* s); // .

int _tmain(int argc, _TCHAR* argv[])
{
// ' .
float* matrix = (float*)malloc(count * count * sizeof(float));
float* vector = (float*)malloc(count * sizeof(float));

//
ReadFile(matrix, count * count, fileIn);
ReadFile(vector, count, fileIn);


int n; float d, y;
float* line; // ,

//
for (int i = 0; i < count - 1; i++)
{
line = &matrix[i * count];
y = vector[i];
// ,
for (int j = i + 1; j < count; j++)
{
n = j * count;
d = matrix[n + i];
// i- j-
for (int k = i; k < count; k++)
{
matrix[n + k] = matrix[n + k] / d * line[i] - line[k];
}
vector[j] = vector[j] / d * line[i] - y;
}
}
//
float* result = (float*)malloc(count * sizeof(float));
float x;

//
for (int i = count - 1; i >= 0; i--)
{
x = vector[i];
n = i * count;
// ϳ i-
for (int j = i + 1; j < count; j++)
{
x -= matrix[n + j];
}
result[i] = x /= matrix[n + i];
// , ,
//
for (int j = 0; j < count; j++)
{
matrix[j * count + i] *= x;
}
}

//
WriteFile(result, count, fileOut);
printf("complited...\n");

//
free(matrix);
free(vector);
free(result);
return 0;
}






. , . () , .
#include "stdafx.h"
#include "mpi.h"
#include "stdio.h"
#include <stdlib.h>
#define count 1024
#define fileIn "D:/temp/tmp/ListNoZero.txt"
#define fileOut "D:/temp/tmp/result.txt"


bool WriteFile(float* a, int n, char* s); // .
bool ReadFile(float* a, int n, char* s); // .

int main(int argc, char* argv[])
{
int p; //
int rc;
rank;//
rc = MPI_Init(&argc,&argv);
if (rc != MPI_SUCCESS)
{
printf ("Error starting MPI program. Terminating.\n");
MPI_Abort(MPI_COMM_WORLD, rc);
}
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

float* matrix = 0;
float* bVector = 0;

// -
if (rank == 0)
{
matrix = (float*)malloc(count * count * sizeof(float));
if (matrix == NULL){ MPI_Finalize(); printf ("not enough memory\n"); return -1; }
bVector = (float*)malloc(count * sizeof(float));
if (bVector == NULL){ MPI_Finalize(); printf ("not enough memory\n"); return -1; }
ReadFile(matrix, count * count, fileIn);
ReadFile(bVector, count, fileIn);
}

//
int *displsA = (int*)malloc(p * sizeof(int));
int *scountsA = (int*)malloc(p * sizeof(int));
int *displsB = (int*)malloc(p * sizeof(int));
int *scountsB = (int*)malloc(p * sizeof(int));
int h, block = count / p;
for (h = 0; h < p; h++)
{
displsA[h] = h * block * count;
scountsA[h] = block * count;
displsB[h] = block * h;
scountsB[h] = block;
}
scountsA[h - 1] += (count % p) * count;
scountsB[h - 1] += (count % p);
block = (rank != (p - 1) ? (count / p) : (count / p + (count % p)));

//
// , block ,
//
float *procMatrix = (float*)malloc(block * count * sizeof(float));
if (procMatrix == NULL){ MPI_Finalize(); printf ("not enough memory\n"); return -1; }
float *procVector = (float*)malloc(block * count * sizeof(float));
if (procVector == NULL){ MPI_Finalize(); printf ("not enough memory\n"); return -1; }

//
MPI_Scatterv(matrix, scountsA, displsA, MPI_FLOAT, procMatrix, block * count, MPI_FLOAT, 0, MPI_COMM_WORLD);
MPI_Scatterv(bVector, scountsB, displsB, MPI_FLOAT, procVector, block, MPI_FLOAT, 0, MPI_COMM_WORLD);

// -
if (rank == 0) {
free(matrix); free(bVector);
free(scountsA); free(displsA);
free(scountsB); free(displsB);
}

//
float* line;
float* msLine;
// , ,
// .
msLine = line = (float*)malloc(count * sizeof(float));
if (msLine == NULL) { MPI_Finalize(); printf ("not enough memory\n"); return -1; }

int n, index = 0, w = count / p; float a, y = 0;
for (int i = 0; i < count - 1; i++){
//
//
if (i / w == rank){
//
msLine = &procMatrix[count * (i % w)];
y = procVector[i % w];
index = rank;
}
else
{
//
if (i / w == p)
{
if (rank == p - 1)
{
//
msLine = &procMatrix[count * (i % w + w)];
y = procVector[i % w + w];
}
else
{
msLine = line;
}
index = p - 1;
}
else
{
//
msLine = line;
index = i / w;
}
}

//
MPI_Bcast(msLine, count, MPI_FLOAT, index, MPI_COMM_WORLD);
MPI_Bcast(&y, 1, MPI_FLOAT, index, MPI_COMM_WORLD);

//
for (int j = 0; j < block; j++){
if (count / p * rank + j > i) {
n = j * count;
a = procMatrix[n + i];
for (int k = i; k < count; k++){
procMatrix[n + k] = procMatrix[n + k] / a * msLine[i] - msLine[k]; }
procVector[j] = procVector[j] / a * msLine[i] - y; }
}
//
// -,
//
if (rank)
{
free(line);
}


//
for (int i = count - 1; i >= 0; i--)
{
if (i / w == rank)
{
y = procVector[i % w];
n = (i % w) * count;
for (int j = i + 1; j < count; j++)
{
y -= procMatrix[n + j];
}
y /= procMatrix[n + i];
index = rank;
}
else
{
if (i / w == p)
{
if (rank == p - 1)
{
y = procVector[i % w + w];
n = (i % w + w) * count;
for (int j = i + 1; j < count; j++)
{
y -= procMatrix[n + j];
}
y /= procMatrix[n + i];
}
index = p - 1;
}
else
{
index = i / w;
}
}

//
MPI_Bcast(&y, 1, MPI_FLOAT, index, MPI_COMM_WORLD);


if (!rank) {//
line[i] = y; }

//
for (int j = 0; j < block; j++)
{
procMatrix[j * count + i] *= y;
}

} //
if (!rank)
{
//
WriteFile(line, count, fileOut);
//printf("complite\n");
    free(line);
}
MPI_Finalize();

return 0;
}




:
    Windows Seven Ultimate SP1;
    AMD Athlon(tm)64 X2 Dual Core Processor 5200+
    RAM 2 Gbyte
    Type OS x32
    ..................



90% antiplagiat.ru, etxt.ru advego.ru




* . , .