src/petscvector/algebra/vector/wrappercomb.cpp
/* perform scale, maxpy and addscalar and store it into given Vec (allocated) */
perform scale, maxpy and addscalar and store it into given Vec (allocated)
perform scale maxpy and addscalar and store it into given Vec ( allocated )
void PetscVectorWrapperComb::compute(const Vec &y, double init_scale){
	if(DEBUG_MODE_PETSCVECTOR >= 100) std::cout << "(WrapperComb)FUNCTION: process(Vec,double)" << std::endl;
	int list_size = get_listsize();
	PetscScalar *alphas;
	Vec *vectors;
	double scale = init_scale; 
	double shift = 0.0;
	int maxpy_length = 0;
	TRYCXX(PetscMalloc(sizeof(PetscScalar)*list_size,&alphas));
	TRYCXX(PetscMalloc(sizeof(Vec)*list_size,&vectors));
	std::list<PetscVectorWrapperCombNode>::iterator list_iter; 
	int j;
	list_iter = comb_list.begin();
	for(j=0;j<list_size;j++){
		if(list_iter->get_vector() == NULL){
			shift += list_iter->get_coeff();
		} else {
			if(list_iter->get_vector() == y){
				scale+=list_iter->get_coeff();
			} else {
				alphas[maxpy_length] = list_iter->get_coeff();
				vectors[maxpy_length] = list_iter->get_vector();
				maxpy_length += 1;
			} 
		}
		if(j < list_size-1){
			list_iter++;
		}
	}
	if(DEBUG_MODE_PETSCVECTOR >= 99){
		std::cout << " - linear combination:" << std::endl;
		std::cout << "  - scale: " << scale << std::endl;
		std::cout << "  - shift: " << shift << std::endl;
		std::cout << "  - maxpy: " << maxpy_length << std::endl;
	}
	if(scale != 1.0){
		TRYCXX( VecScale(y, scale) );
	}
	if(shift != 0.0){
		TRYCXX( VecShift(y, shift) );
	}
	if(maxpy_length > 0){
		TRYCXX( VecMAXPY(y,maxpy_length,alphas,vectors) );
	}
	TRYCXX(PetscFree(alphas));
	TRYCXX(PetscFree(vectors));
}
void PetscVectorWrapperComb :: compute ( const Vec & y , double init_scale ) { if ( DEBUG_MODE_PETSCVECTOR >= 100 ) std :: cout << " " << std :: endl ; int list_size = get_listsize ( ) ; PetscScalar * alphas ; Vec * vectors ; double scale = init_scale ; double shift = 0.0 ; int maxpy_length = 0 ; TRYCXX ( PetscMalloc ( sizeof ( PetscScalar ) * list_size , & alphas ) ) ; TRYCXX ( PetscMalloc ( sizeof ( Vec ) * list_size , & vectors ) ) ; std :: list < PetscVectorWrapperCombNode > :: iterator list_iter ; int j ; list_iter = comb_list . begin ( ) ; for ( j = 0 ; j < list_size ; j ++ ) { if ( list_iter -> get_vector ( ) == NULL ) { shift += list_iter -> get_coeff ( ) ; } else { if ( list_iter -> get_vector ( ) == y ) { scale += list_iter -> get_coeff ( ) ; } else { alphas [ maxpy_length ] = list_iter -> get_coeff ( ) ; vectors [ maxpy_length ] = list_iter -> get_vector ( ) ; maxpy_length += 1 ; } } if ( j < list_size - 1 ) { list_iter ++ ; } } if ( DEBUG_MODE_PETSCVECTOR >= 99 ) { std :: cout << " " << std :: endl ; std :: cout << " " << scale << std :: endl ; std :: cout << " " << shift << std :: endl ; std :: cout << " " << maxpy_length << std :: endl ; } if ( scale != 1.0 ) { TRYCXX ( VecScale ( y , scale ) ) ; } if ( shift != 0.0 ) { TRYCXX ( VecShift ( y , shift ) ) ; } if ( maxpy_length > 0 ) { TRYCXX ( VecMAXPY ( y , maxpy_length , alphas , vectors ) ) ; } TRYCXX ( PetscFree ( alphas ) ) ; TRYCXX ( PetscFree ( vectors ) ) ; }
perform scale, maxpy and addscalar and store it into given Vec (allocated)
perform scale maxpy and addscalar and store it into given Vec ( allocated )
/* = 0.0 if y=comb, = 1.0 if y+=comb */ /* go throught the list:
	 * - if same vector => scale += coeff
	 * - if scalar (NULL Vec) => shift += coeff
	 * - otherwise prepare to array to maxpy
	 * 
	 * afterwards
	 * y = scale*y (VecScale)
	 * y = y + shift (VecShift)
	 * y += alphas*vectors (VecMAXPY)
	 */ /* allocate memory */ /* get array with coefficients and vectors */ /* iterator through list */ /* set iterator to the begin of the list */ /* go through the list and fill the vectors */ /* if Vec==NULL, then add to the shift */ /* if same vector => scale += coeff */ /* otherwise prepare to maxpy-arrays */ /* this is not the last element */ /* print info about performed stuff */ /* there will be maxy y+=..., it is necessary to change scale coeff */ //	if(maxpy_length > 0){ //		scale += -1.0; //	} /* scale the vector */ /* shift by scalar value */ /* y += sum (alphas*vectors) */ /* free memory */