Пример #1
0
/*
   --------------------------------------------------------
   purpose -- assemble any aggregates in the aggregate list

   created -- 98mar26, cca
   --------------------------------------------------------
*/
static void
assembleAggregates (
   int             J,
   SubMtx          *BJ,
   SubMtxList      *aggList,
   SubMtxManager   *mtxmanager,
   int             msglvl, 
   FILE            *msgFile
) {
SubMtx     *BJhat, *BJhead ;
double   *entBJ, *entBJhat ;
int      inc1, inc1hat, inc2, inc2hat, ncol, ncolhat, nrow, nrowhat ;
 
if ( BJ == NULL || aggList == NULL ) {
   fprintf(stderr,
          "\n fatal error in assembleAggregates()"
          "\n BJ = %p, aggList = %p", BJ, aggList) ;
   exit(-1) ;
}
if ( SubMtxList_isListNonempty(aggList, BJ->rowid) ) {
   if ( msglvl > 3 ) {
      fprintf(msgFile, "\n\n aggregate list is not-empty") ;
      fflush(msgFile) ;
   }
   SubMtx_denseInfo(BJ, &nrow, &ncol, &inc1, &inc2, &entBJ) ;
   if ( msglvl > 2 ) {
      fprintf(msgFile,
          "\n\n BJ(%d,%d) : nrow %d, ncol %d, inc1 %d, inc2 %d, ent %p",
          BJ->rowid, BJ->colid, nrow, ncol, inc1, inc2, entBJ) ;
      fflush(msgFile) ;
   }
   BJhead = SubMtxList_getList(aggList, J) ;
   for ( BJhat = BJhead ; BJhat != NULL ; BJhat = BJhat->next ) {
      if ( BJhat == NULL ) {
         fprintf(stderr,
                 "\n 3. fatal error in forwardVisit(%d)"
                 "\n BJhat = NULL", J) ;
         exit(-1) ;
      }
      SubMtx_denseInfo(BJhat, &nrowhat, &ncolhat, &inc1hat, &inc2hat,
                       &entBJhat) ;
      if ( msglvl > 2 ) {
         fprintf(msgFile,
         "\n BJhat(%d,%d) : nrow %d, ncol %d, inc1 %d, inc2 %d, ent %p",
           BJhat->rowid, BJhat->colid,
           nrowhat, ncolhat, inc1hat, inc2hat, entBJhat) ;
         fflush(msgFile) ;
      }
      if ( nrow != nrowhat || ncol != ncolhat
         || inc1 != inc1hat || inc2 != inc2hat || entBJhat == NULL ) {
         fprintf(stderr, "\n fatal error") ;
         exit(-1) ;
      }
      if ( msglvl > 3 ) {
         fprintf(msgFile, "\n\n BJ") ;
         SubMtx_writeForHumanEye(BJ, msgFile) ;
         fprintf(msgFile, "\n\n BJhat") ;
         SubMtx_writeForHumanEye(BJhat, msgFile) ;
         fflush(msgFile) ;
      }
      if ( SUBMTX_IS_REAL(BJhat) ) {
         DVadd(nrow*ncol, entBJ, entBJhat) ;
      } else if ( SUBMTX_IS_COMPLEX(BJhat) ) {
         DVadd(2*nrow*ncol, entBJ, entBJhat) ;
      }
   }
   SubMtxManager_releaseListOfObjects(mtxmanager, BJhead) ;
   if ( msglvl > 3 ) {
      fprintf(msgFile, "\n\n BJ after assembly") ;
      SubMtx_writeForHumanEye(BJ, msgFile) ;
      fflush(msgFile) ;
   }
}
return ; }
Пример #2
0
/*--------------------------------------------------------------------*/
static void
InpMtx_MT_mmm (
   int        flag,
   InpMtx     *A,
   DenseMtx   *Y,
   double     alpha[],
   DenseMtx   *X,
   int        nthread,
   int        msglvl,
   FILE       *msgFile
) {
double     t1, t2 ;
int        myid, nent, rc ;
MTmvmObj   *MTmvmObjs, *obj ;
/*
   -------------------------------
   set up the nthread data objects
   -------------------------------
*/
MARKTIME(t1) ;
MTmvmObjs = setup(A, Y, alpha, X, nthread) ;
MARKTIME(t2) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n %% CPU %8.3f : setup time", t2 - t1) ;
}
#if THREAD_TYPE == TT_POSIX 
{
pthread_t        *tids ;
pthread_attr_t   attr  ;
void             *status ;
/*
#####   NOTE: for SGI machines, this command must be present
#####         for the thread scheduling to be efficient.
#####         this is NOT a POSIX call, but SGI needs it anyway
pthread_setconcurrency(nthread) ;
*/
pthread_attr_init(&attr) ;
/*
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) ;
*/
pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS) ;
ALLOCATE(tids, pthread_t, nthread) ;
MARKTIME(t1) ;
for ( myid = 0, obj = MTmvmObjs ; myid < nthread ; myid++, obj++ ) {
   switch ( flag ) {
   case NONSYM :
      rc = pthread_create(&tids[myid], &attr, worker_nonsym_mmm, obj) ;
      break ;
   case SYM :
      rc = pthread_create(&tids[myid], &attr, worker_sym_mmm, obj) ;
      break ;
   case HERM :
      rc = pthread_create(&tids[myid], &attr, worker_herm_mmm, obj) ;
      break ;
   case NONSYM_T :
      rc = pthread_create(&tids[myid], &attr, worker_nonsym_mmm_T, obj);
      break ;
   case NONSYM_H :
      rc = pthread_create(&tids[myid], &attr, worker_nonsym_mmm_H, obj);
      break ;
   }
   if ( rc != 0 ) {
      fprintf(stderr, 
           "\n fatal error, myid = %d, rc = %d from pthread_create",
           myid, rc) ;
      exit(-1) ;
   } else if ( msglvl > 2 ) {
      fprintf(stderr, "\n %% thread %d created", myid) ;
   }
}
MARKTIME(t2) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n %% CPU %8.3f : thread creation time", t2 - t1) ;
}
MARKTIME(t1) ;
for ( myid = 0 ; myid < nthread ; myid++ ) {
   pthread_join(tids[myid], &status) ;
}
MARKTIME(t2) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, "\n %% CPU %8.3f : thread join time", t2 - t1) ;
}
FREE(tids) ;
pthread_attr_destroy(&attr) ;
}
#endif
/*
   -------------------------------------
   accumulate the rhs hand side matrices
   -------------------------------------
*/
MARKTIME(t1) ;
nent = Y->nrow * Y->ncol ;
for ( myid = 1, obj = MTmvmObjs + 1 ; 
      myid < nthread ; 
      myid++, obj++ ) {
   if ( INPMTX_IS_REAL_ENTRIES(A) ) {
      DVadd(nent, DenseMtx_entries(Y), DenseMtx_entries(obj->Y)) ;
   } else if ( INPMTX_IS_COMPLEX_ENTRIES(A) ) {
      DVadd(2*nent, DenseMtx_entries(Y), DenseMtx_entries(obj->Y)) ;
   }
}
MARKTIME(t2) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, 
           "\n %% CPU %8.3f : time to accumulate rhs", t2 - t1) ;
}
/*
   ---------------------------
   release the data structures
   ---------------------------
*/
MARKTIME(t1) ;
for ( myid = 0, obj = MTmvmObjs ; myid < nthread ; myid++, obj++ ) {
   InpMtx_free(obj->A) ;
   if ( myid > 0 ) {
      DenseMtx_free(obj->Y) ;
   }
}
FREE(MTmvmObjs) ;
MARKTIME(t2) ;
if ( msglvl > 0 ) {
   fprintf(msgFile, 
           "\n %% CPU %8.3f : time to release and free data", t2 - t1) ;
}
return ; }