T* parallel_strassen_matrix_multiplier<T>::mult (const T *m, const T *n, size_t arows, size_t acols, size_t brows, size_t bcols) { /* Make sure this is a valid multiplication */ if (acols == brows) { /* Check to see if these matrices are already square and have dimensions of a power of 2. If not, * the matrices must be resized and padded with zeroes to meet this criteria. */ if (arows == acols && brows == bcols && !(arows & (arows - 1))) { /* Call __mult with an ID of 0 */ T *C = __mult (m, n, arows, 0); return C; } else { size_t N; size_t max_term = acols; T *A = NULL; T *B = NULL; T *C = NULL; if (arows >= acols && arows >= brows) max_term = arows; else if (acols >= arows && acols >= bcols) max_term = acols; else if (brows >= bcols && brows >= arows) max_term = brows; else if (bcols >= brows && bcols >= acols) max_term = bcols; /* Find the nearest power of 2 greater than the largest dimension of these matrices */ N = std::pow (2, (size_t) (std::log (max_term) / strassen_matrix_multiplier<T>::__log2) + 1); /* If m needs padding, pad it */ if (arows != acols || arows & (arows - 1)) A = __pad (m, arows, acols, N); /* If n needs padding, pad it */ if (brows != brows || brows & (brows - 1)) B = __pad (n, brows, bcols, N); /* __mult does the actual multiplication work - call with ID of 0 to identify this as the * main thread. */ if (A && B) C = __mult (A, B, N, 0); else if (A) C = __mult (A, n, N, 0); else if (B) C = __mult (m, B, N, 0); /* Extract the non-zero elements out of C and put them into a new matrix D which is * of the size arows x bcols */ T *D = __unpad (C, arows, arows, N); if (A) free (A); if (B) free (B); free (C); return D; } } return NULL; }
/** * Prints one block of the instance in vector mode (standard). */ INT32 CGEN_PRIVATE CData_PrintVectors_Block ( CData* _this, /* Pointer to data instance */ INT32 nBlock /* Block index (<0: ignore blocks) */ ) /* Returns number of lines printed */ { INT32 i = 0; /* Universal loop counter */ INT32 nR = 0; /* Current record */ INT32 nR_ = 0; /* First record to be printed */ INT32 nR0 = 0; /* First record of current page */ INT32 nSR = 0; /* Number of records of currenr page */ INT32 nXR = 0; /* Last record to print plus one */ INT32 nC = 0; /* Current component */ INT32 nXC = 0; /* Number of components */ INT32 nWI = 0; /* Component index column width */ INT32 nW0 = 0; /* Head column width */ INT32 nW = 0; /* Column width */ INT32 nP = 0; /* Current page */ INT32 nPps = 0; /* Pages per screen */ INT32 nL = 0; /* Line counter */ BOOL bPur = FALSE; /* Print physical record unit flag */ BOOL bPuc = FALSE; /* Print physical component unit flg.*/ FLOAT64 nBuf = 0.; /* Double buffer */ char sBuf[L_SSTR+1]; /* String buffer */ /* Validate */ /* --------------------------------- */ if (nBlock>=CData_GetNBlocks(_this)) return 0; /* Requested block does not exist */ /* Initialize */ /* --------------------------------- */ nR_ = nBlock>=0 ? CData_GetNRecsPerBlock(_this)*nBlock : 0; /* Get first record to print */ nXR = nBlock>=0 ? nR_+CData_GetNRecsPerBlock(_this) : CData_GetNRecs(_this); /* Get number of records */ nXC = CData_GetNComps(_this); /* Get number of components */ bPur = _this->m_lpTable->m_fsr!=1. && _this->m_lpTable->m_fsr!=0.; /* Displaying physical record units? */ bPuc = _this->m_nCinc!=1. && _this->m_nCinc!=0.; /* Displaying physical comp. units? */ nPps = dlp_maxprintlines()/(nXC+4); /* Compute no. of pages per sceeen */ /* Print vectors */ /* --------------------------------- */ if (nBlock>=0) /* Printing blockwise? */ { /* >> */ printf("\n Block %ld (offset %ld)",(long)nBlock,(long)nR_); /* Show current block index */ dlp_inc_printlines(1); nL++; /* Adjust number of printed lines */ } /* << */ for (nR0=nR_; nR0<nXR; ) /* Loop over records */ { /* >> */ CData_PrintVectors_GetColWidth(_this,nR0,0,&nWI,&nW0,&nW); /* Comp. head and data col. widths */ nSR = (dlp_maxprintcols()-nWI-nW0-4)/(nW+1); /* Number of columns to print */ if (nR0+nSR>nXR) nSR = nXR-nR0; /* No more than there are records! */ /* Print record header */ /* - - - - - - - - - - - - - - - - */ if (bPur) /* Display physical record units? */ { /* >> */ printf("\n %s ->",__pad(strcpy(sBuf,_this->m_lpRunit),nW0+nWI,'r')); /* Print name of physical unit */ for (nR=nR0; nR<nR0+nSR; nR++) /* Loop over remaining records */ { /* >> */ nBuf = _this->m_lpTable->m_ofs + (nR-nR_)*_this->m_lpTable->m_fsr; /* Compute abscissa value */ __sprintx(sBuf,&nBuf,T_DOUBLE,_this->m_bExact); /* Print to a string */ printf("%s ",__pad(sBuf,nW,'r')); /* Format and print to screen */ } /* << */ dlp_inc_printlines(1); nL++; /* Adjust number of printed lines*/ } /* << */ sBuf[0]='\0'; /* Clear string buffer */ if (bPuc) sprintf(sBuf,"%s| ",_this->m_lpCunit); /* Print phys. comp. unit name... */ printf("\n %s",__pad(sBuf,nW0+nWI+3,'r')); /* ... or empty string */ for (nR=nR0; nR<nR0+nSR; nR++) /* Loop over remaining records */ { /* >> */ i=nR-nR_; __sprintx(sBuf,&i,T_INT,_this->m_bExact); /* Print record index to a str. */ printf("%s%c",__pad(sBuf,nW,'r'),CData_RecIsMarked(_this,nR)?'*':' '); /* Format and print to screen */ } /* << */ sBuf[0]='\0'; /* Clear string buffer */ if (bPuc) sprintf(sBuf,"%c ",bPuc?'v':' '); /* Print down arrow ... */ printf("\n %s",__pad(sBuf,nW0+nWI+3,'r')); /* ... or empty string */ sBuf[0]='\0'; for (i=0; i<nW; i++) sBuf[i]='.'; sBuf[i]='\0'; /* Make horizonal delimiter */ for (nR=nR0; nR<nR0+nSR; nR++) printf("%s ",sBuf); /* Print one per vector */ dlp_inc_printlines(2); nL+=2; /* Adjust number of printed lines */ /* Print data */ /* - - - - - - - - - - - - - - - - */ for (nC=0; nC<nXC; ) /* Loop over components */ { /* >> */ __sprintx(sBuf,&nC,T_INT,_this->m_bExact); /* Print comp. index to a string */ printf("\n%c%s ", /* Format and print to screen */ CData_CompIsMarked(_this,nC)?'*':' ',__pad(sBuf,nWI,'r')); /* | (incl. "*" for "marked") */ if (bPuc && dlp_is_numeric_type_code(CData_GetCompType(_this,nC))) /* Display ordinate value? */ { /* >> */ nBuf = _this->m_nCofs + nC*_this->m_nCinc; /* Compute it */ __sprintx(sBuf,&nBuf,T_DOUBLE,_this->m_bExact); /* Print it to a string */ } /* << */ else strcpy(sBuf,CData_GetCname(_this,nC)); /* else display component name */ printf("%s: ",__pad(dlp_strtrimleft(dlp_strtrimright(sBuf)),nW0,'r')); /* Format and print to screen */ for (nR=nR0; nR<nR0+nSR; nR++) /* Loop over remaining records */ { /* >> */ __sprintx(sBuf,CData_XAddr(_this,nR,nC), /* Print cell value to a str. */ CData_GetCompType(_this,nC),_this->m_bExact); /* | */ if (dlp_is_symbolic_type_code(CData_GetCompType(_this,nC))) /* Is string value */ if ((INT32)dlp_strlen(sBuf)>nW) /* Will not fit in column */ dlp_strabbrv(sBuf,sBuf,nW); /* Abbreviate it */ if (dlp_is_numeric_type_code(CData_GetCompType(_this,nC))) /* Is numeric value */ if (_this->m_bNz && CMPLX_EQUAL(CData_Cfetch(_this,nR,nC),CMPLX(0.))) dlp_strcpy(sBuf,"-"); printf("%s%c",__pad(sBuf,nW,'r'), /* Format and print to screen */ CData_CellIsMarked(_this,nR*CData_GetNComps(_this)+nC)?'*':' '); /* | (incl. "*" for "marked") */ } /* << */ dlp_inc_printlines(1); nL++; /* Adjust number of printed lines*/ /* Break component listing */ /* - - - - - - - - - - - - - - - */ if (nPps==0) /* Not all comps. fit on screen */ { /* >> */ sprintf(sBuf,"component (0..%ld), cancel -3",(long)nXC-1); /* Make user hint */ if ((nC=dlp_printstop_nix(nC,sBuf,NULL))==-1) break; /* Break listing */ if (nC< -2 ) return -1; /* Cancelled by user */ if (nC>=nXC) break; /* No more components -> break */ } /* << */ else nC++; /* No breaking -> count comps. */ } /* << */ nR0+=nSR; /* First record on next page */ nP++; /* Count pages */ if (nR0<nXR) /* There are more records */ { /* >> */ printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); /* Print a separator */ dlp_inc_printlines(1); nL++; /* Adjust number of printed lines*/ } /* << */ /* Break record listing */ /* - - - - - - - - - - - - - - - - */ if (((nPps>0 && nP>=nPps) || nPps==0) && nR0<nXR) /* Complicated break condition :) */ { /* >> */ dlp_inc_printlines(dlp_maxprintlines()); /* Do stop right here */ sprintf(sBuf,"record (%ld..%ld)%s",(long)nR_,(long)nXR-1, /* Make user hint */ nBlock>=0?", cancel -3":""); /* | */ if ((nR0=dlp_printstop_nix(--nR0,sBuf,NULL))==-1) break; /* Break listing */ if (nR0< -2 ) return -1; /* Cancelled by user */ if (nR0< nR_) nR0=nR_; /* No previous blocks, please! */ if (nR0>=nXR) break; /* No more records -> break */ nP=0; /* Reset page counter */ } /* << */ } /* << */ return nL; /* Return number of printed lines */ }