43 int MatInit(
Mat *A,
int m,
int nnz,
int *indices,
double *values,
int flag
157 MPI_Comm_rank(mat->
comm, &rank);
164 sprintf(fn,
"%s_%d.dat", filename, rank);
168 printf(
"cannot open file %s", fn);
171 while(feof(in)== 0 && i< (mat->
m * mat->
nnz)){
175 else if(mat->
nnz==2){
183 if(i!= mat->
m * mat->
nnz ){
184 printf(
"WARNNING data size doesn't fit\n");
207 MPI_Comm_rank(mat->
comm, &rank);
209 sprintf(fn,
"%s_%d.dat", filename, rank);
213 printf(
"cannot open file %s", fn);
216 for(i=0; i < (mat->
nnz * mat->
m); i+=mat->
nnz){
217 for(j=0; j< mat->
nnz ; j++){
218 fprintf(out,
"%d ",mat->
indices[i+j]);
219 fprintf(out,
"%f ", mat->
values[i+j]);
242 tmp_indices = (
int *) malloc(A->
m * A->
nnz *
sizeof(
int));
243 memcpy(tmp_indices, A->
indices, A->
m * A->
nnz *
sizeof(
int));
270 MPI_Comm_size(A->
comm, &size);
276 A->
S = (
int** ) malloc(A->
steps *
sizeof(
int* ));
277 A->
R = (
int** ) malloc(A->
steps *
sizeof(
int* ));
278 A->
nS = (
int* ) malloc(A->
steps *
sizeof(
int));
279 A->
nR = (
int* ) malloc(A->
steps *
sizeof(
int));
284 A->
S = (
int** ) malloc(A->
steps *
sizeof(
int* ));
285 A->
R = (
int** ) malloc(A->
steps *
sizeof(
int* ));
286 A->
nS = (
int* ) malloc(A->
steps *
sizeof(
int));
287 A->
nR = (
int* ) malloc(A->
steps *
sizeof(
int));
294 A->
S = (
int** ) malloc(A->
steps *
sizeof(
int* ));
295 A->
R = (
int** ) malloc(A->
steps *
sizeof(
int* ));
296 A->
nS = (
int* ) malloc(A->
steps *
sizeof(
int));
297 A->
nR = (
int* ) malloc(A->
steps *
sizeof(
int));
304 A->
S = (
int** ) malloc(A->
steps *
sizeof(
int* ));
305 A->
R = (
int** ) malloc(A->
steps *
sizeof(
int* ));
306 A->
nS = (
int* ) malloc(A->
steps *
sizeof(
int));
307 A->
nR = (
int* ) malloc(A->
steps *
sizeof(
int));
314 A->
S = (
int** ) malloc(A->
steps *
sizeof(
int* ));
315 A->
R = (
int** ) malloc(A->
steps *
sizeof(
int* ));
316 A->
nS = (
int* ) malloc(A->
steps *
sizeof(
int));
317 A->
nR = (
int* ) malloc(A->
steps *
sizeof(
int));
324 MPI_Allreduce(&A->
lindices[0], &min, 1, MPI_INT, MPI_MIN, A->
comm);
329 while( j<A->com_count && i<A->lcount){
330 if(min+j < A->lindices[i]){
354 for(i=0; i<A->
m; i++)
358 for(i=0; i<A->
m*A->
nnz; i+=A->
nnz){
359 for(j=0; j<A->
nnz; j++){
381 int i, j, e, rank, size;
382 int *rbuf, rbufcount;
383 double *rbufvalues, *lvalues;
385 MPI_Request s_request, r_request;
388 MPI_Comm_rank(A->
comm, &rank);
389 MPI_Comm_size(A->
comm, &size);
390 lvalues = (
double *) malloc( A->
lcount *
sizeof(
double));
391 for(i=0; i < A->
lcount; i++)
395 for(i=0; i<A->
m; i++){
396 for(j=0; j<A->
nnz; j++){
401 memcpy(x, lvalues, (A->
lcount)*
sizeof(
double));
402 MPI_Allreduce(&(A->
lcount), &(rbufcount), 1, MPI_INT, MPI_MAX, A->
comm);
404 rbuf = (
int *) malloc(rbufcount *
sizeof(
int));
405 rbufvalues = (
double *) malloc(rbufcount *
sizeof(
double));
408 for (p=1; p < size; p++){
409 rp = (size + rank - p)%size;
410 sp = (rank + p)%size;
411 MPI_Send(&(A->
lcount), 1, MPI_INT, sp, 0, A->
comm);
412 MPI_Recv(&rbufcount, 1, MPI_INT, rp, 0, A->
comm, &status);
414 MPI_Irecv(rbuf, rbufcount, MPI_INT, rp, tag, A->
comm, &r_request);
416 MPI_Wait(&r_request, &status);
417 MPI_Wait(&s_request, &status);
419 MPI_Irecv(rbufvalues, rbufcount, MPI_DOUBLE, rp, tag, A->
comm, &r_request);
420 MPI_Isend(lvalues, A->
lcount, MPI_DOUBLE, sp, tag, A->
comm, &s_request);
422 MPI_Wait(&r_request, &status);
424 MPI_Wait(&s_request, &status);
451 for(i=0; i < A->
lcount; i++)
455 for(i=0; i< A->
m*A->
nnz; i+=A->
nnz){
456 for(j=0; j< A->
nnz; j++){
485 int nnzline, sparsity, maxline, maxsize;
490 MPI_Comm_rank(mat->
comm, &rank);
491 MPI_Comm_size(mat->
comm, &size);
495 sprintf(fn,
"%s_%s", filename,
"info.txt");
498 printf(
"cannot open file %s\n", fn);
501 printf(
"open file %s ...", fn);
502 fprintf(out,
"flag %d\n", mat->
flag);
503 fprintf(out,
"rows %d\n ", mat->
m);
504 fprintf(out,
"nnz %d\n", mat->
nnz);
508 n = (
int* ) calloc(mat->
lcount,
sizeof(
int));
510 MPI_Gather(&(mat->
lcount), 1, MPI_INT, n, 1, MPI_INT, master, mat->
comm);
514 fprintf(out,
"cols :\n");
515 for(i=0; i<size; i++)
516 fprintf(out,
"%d ", n[i]);
523 for(i=0; i<mat->
steps; i++){
528 if(mat->
nS[i]>maxline)
529 maxline = mat->
nS[i];
532 MPI_Reduce(&nnzline, &sparsity, 1, MPI_INT, MPI_SUM, 0, mat->
comm);
533 MPI_Reduce(&maxline, &maxsize, 1, MPI_INT, MPI_MAX, 0, mat->
comm);
535 fprintf(out,
"sparsity %d\n", sparsity);
536 fprintf(out,
"maxsize %d\n ", maxsize);
540 s = (
int* ) calloc((mat->
steps),
sizeof(int));
541 MPI_Reduce(mat->
nS, s, mat->
steps, MPI_INT, MPI_SUM, 0, mat->
comm);
544 fprintf(out,
"sumsteps :\n");
545 for(i=0; i<mat->
steps; i++)
546 fprintf(out,
"%d ", s[i]);
552 sr = (
int* ) calloc((mat->
steps)*size,
sizeof(int));
554 MPI_Gather(mat->
nS, mat->
steps, MPI_INT, sr, mat->
steps, MPI_INT, master, mat->
comm);
558 fprintf(out,
"send/receive matrix\n");
559 for(i=0; i<size; i++){
560 if(mat->
flag==BUTTERFLY){
561 for(j=0; j<size; j++){
564 fprintf(out,
"%d ", sr[i*(mat->
steps)+
log_2(j-i)]);
566 fprintf(out,
"%d ", 0);
570 fprintf(out,
"%d ", sr[i*(mat->
steps)+
log_2(size+j-i)]);
572 fprintf(out,
"%d ", 0);
575 fprintf(out,
"%d ", 0);
581 for(j=0; j<size; j++){
583 fprintf(out,
"%d ", sr[i*(mat->
steps)+j-i]);
586 fprintf(out,
"%d ", sr[(i+1)*(mat->
steps)-i+j]);
589 fprintf(out,
"%d ", 0);
601 printf(
"close\n", fn);
614 lvalues = (
double *) malloc(A->
lcount *
sizeof(
double));
615 memcpy(lvalues, x, (A->
lcount) *
sizeof(
double));
621 for(k=0; k< A->
steps; k++)
624 for(k=0; k< A->
steps; k++)
627 com_val=(
double *) malloc( A->
com_count *
sizeof(
double));
636 for(k=1; k< A->
steps; k++)
646 for(k=1; k< A->
steps; k++)
652 com_val=(
double *) malloc( A->
com_count *
sizeof(
double));
653 out_val=(
double *) malloc( A->
com_count *
sizeof(
double));
662 MPI_Allreduce(com_val, out_val, A->
com_count, MPI_DOUBLE, MPI_SUM, A->
comm);