model-layer/scalable-mf-module/OCAM/ocam.cpp
/*
	Out-of-core Cyclic Coordinate Descent (CCD) for matrix completion 
*/
Out-of-core Cyclic Coordinate Descent (CCD) for matrix completion
Out - of - core Cyclic Coordinate Descent ( CCD ) for matrix completion
void ocam(const char *gcsc_filename, dmat_t W, dmat_t H, testset_t &T, parameter &param){
	const bool isRow = true;
	int k = param.k;
	int maxiter = param.maxiter;
	int gridSize = param.grids;
	int num_threads_old = omp_get_num_threads();
	RVALTYPE lambda = param.lambda;
	long num_updates = 0;
	int dims = k;
	omp_set_num_threads(param.threads);
	for(int oiter = 1; oiter <= maxiter; oiter++) {
		Tstart = omp_get_wtime();
		if(param.do_opt) {
			if(oiter <= 3)	dims = (int)k/8;
			else	dims = k;
		}
#pragma omp parallel for schedule(coarsegrained) shared(W,H)
		for(int i=0; i<gridSize; i++) {
			PartitionUpdate(gcsc_filename, gridSize, i, W, H, lambda, dims, isRow);
			system("sync");
			system("echo 3 > /proc/sys/vm/drop_caches");
		}
#pragma omp parallel for schedule(coarsegrained) shared(W,H)
		for(int i=0; i<gridSize; i++) {
			PartitionUpdate(gcsc_filename, gridSize, i, W, H, lambda, dims, !isRow);
			system("sync");
			system("echo 3 > /proc/sys/vm/drop_caches");
		}
		Ttime += omp_get_wtime() - Tstart;
		printf("%d\t%.10g\t", oiter, Ttime);
		if(T.nnz != 0){
			printf("%.10g", calrmse(T, W, H, k, false));
		}
		puts("");
		fflush(stdout);
	}
	omp_set_num_threads(num_threads_old);
}
void ocam ( const char * gcsc_filename , dmat_t W , dmat_t H , testset_t & T , parameter & param ) { const bool isRow = true ; int k = param . k ; int maxiter = param . maxiter ; int gridSize = param . grids ; int num_threads_old = omp_get_num_threads ( ) ; RVALTYPE lambda = param . lambda ; long num_updates = 0 ; int dims = k ; omp_set_num_threads ( param . threads ) ; for ( int oiter = 1 ; oiter <= maxiter ; oiter ++ ) { Tstart = omp_get_wtime ( ) ; if ( param . do_opt ) { if ( oiter <= 3 ) dims = ( int ) k / 8 ; else dims = k ; } #pragma  omp parallel for schedule(coarsegrained) shared(W,H) for ( int i = 0 ; i < gridSize ; i ++ ) { PartitionUpdate ( gcsc_filename , gridSize , i , W , H , lambda , dims , isRow ) ; system ( " " ) ; system ( " " ) ; } #pragma  omp parallel for schedule(coarsegrained) shared(W,H) for ( int i = 0 ; i < gridSize ; i ++ ) { PartitionUpdate ( gcsc_filename , gridSize , i , W , H , lambda , dims , ! isRow ) ; system ( " " ) ; system ( " " ) ; } Ttime += omp_get_wtime ( ) - Tstart ; printf ( " \t \t " , oiter , Ttime ) ; if ( T . nnz != 0 ) { printf ( " " , calrmse ( T , W , H , k , false ) ) ; } puts ( " " ) ; fflush ( stdout ) ; } omp_set_num_threads ( num_threads_old ) ; }
Out-of-core Cyclic Coordinate Descent (CCD) for matrix completion
Out - of - core Cyclic Coordinate Descent ( CCD ) for matrix completion
// Update the factor matrix H // Update the factor matrix W