File: compute.c

package info (click to toggle)
armci-mpi 0.0~git20180917-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,768 kB
  • sloc: ansic: 12,777; sh: 236; makefile: 54; fortran: 44
file content (118 lines) | stat: -rw-r--r-- 2,860 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include <armci.h>
#include "mp3.h"

extern int na,nz;
extern int me, nproc;
extern int myfirstrow,mylastrow;

void computeminverse(double *minvptr,double *aptr,int *rowptr,int *colptr)
{
int i,j;
    for(i=myfirstrow;i<=mylastrow;i++){
      for(j=rowptr[i];j<rowptr[i+1];j++){
        if(colptr[j]>=i){
          if(colptr[j]==i){
            /*printf("\n%d:i=%d j=%d aptr=%f",me,i,j,aptr[j]);*/
            minvptr[i]=10.0/aptr[j];
          }
          if(colptr[j]>i){
            minvptr[i]=0.0;
            /*printf("\n%d:l=%d i=%d mycolptr[j]=%d",me,j,i,colptr[j]);*/
          }
          break;
        }
      }
    }
    /*MP_BARRIER();*/
}

void computeminverser(double *minvptr,double *rvecptr,double *minvrptr)
{
int i;
    for(i=myfirstrow;i<=mylastrow;i++)
       minvrptr[i]=minvptr[i]*rvecptr[i];
    /*MP_BARRIER();*/
}

void acg_printvec2(char *v, double *vec, char *v1, double *vec1)
{
int i;
    for(i=myfirstrow;i<=mylastrow;i++)
      printf("\n%d:%s[%d]=%f %s[%d]=%f",me,v,i,vec[i],v1,i,vec1[i]);
    fflush(stdout);
    MP_BARRIER();
}

void acg_printvec(char *v, double *vec)
{
int i;
    for(i=myfirstrow;i<=mylastrow;i++)
      printf("\n%d:%s[%d]=%f",me,v,i,vec[i]);
    fflush(stdout);
    MP_BARRIER();
}

double acg_ddot(double *vec1,double *vec2)
{
int i;
double dt=0.0;
    for(i=myfirstrow;i<=mylastrow;i++)
      dt+=(vec1[i]*vec2[i]);
    armci_msg_dgop(&dt,1,"+");
    /*MP_BARRIER();*/
    return(dt);
}


void acg_zero(double *vec1)
{
int i;
    for(i=myfirstrow;i<=mylastrow;i++)
      vec1[i]=0.0;
    MP_BARRIER();
}

void acg_addvec(double *pscale1,double *vec1,double *pscale2,double *vec2, double *result)
{
int i;
double scale1=*pscale1,scale2=*pscale2;
    for(i=myfirstrow;i<=mylastrow;i++)
      result[i]=(scale1*vec1[i]+scale2*vec2[i]);
    /*MP_BARRIER();*/
}

void acg_2addvec(double *pscale1a,double *vec1a, double *pscale2a,double *vec2a,
        double *resulta, 
                double *pscale1b, double *vec1b,double *pscale2b, double *vec2b,
        double *resultb, 
        int *rowptr, int *colptr)
{
int i;
double scale1a=*pscale1a,scale2a=*pscale2a, scale1b=*pscale1b,scale2b=*pscale2b;
    for(i=myfirstrow;i<=mylastrow;i++){
      resulta[i]=vec1a[i]*scale1a+vec2a[i]*scale2a;
      resultb[i]=vec1b[i]*scale1b+vec2b[i]*scale2b;
    }
    /*MP_BARRIER();*/
}

void acg_matvecmul(double *aptr,double *vec, double *result,int *rowptr, int *colptr)
{
int i,j;
double tmprowsum=0.0;
    ARMCI_Barrier();
    for(i=myfirstrow;i<=mylastrow;i++){
       for(j=rowptr[i];j<rowptr[i+1];j++){
         tmprowsum=tmprowsum+aptr[j]*vec[colptr[j]];
         /*printf("\n%d:%d %d %f %f %f",
            me,j,colptr[j],aptr[j],vec[colptr[j]],tmprowsum);*/
       }
       result[i]=tmprowsum;
       tmprowsum=0.0;
    }
    /*ARMCI_Barrier();*/
}