model-layer/scalable-tf-module/FTcom/Tensor.cpp
/* Write the subtensor (i.e., X_g[g_1, g_2, ..., g_N]) to a grid-based tensor file */
Write the subtensor  to a grid-based tensor file
Write the subtensor to a grid - based tensor file
off_t SubTensor::writeSubTensorToGTF(const int fd, int cellIdx, int *gridIdx, int **gridDims) {
	int gridSize, order, cntSize = 0;
	off_t gridOffset;
	off_t writeSize;
	pread(fd, &gridSize, sizeof(int), 0);
	pread(fd, &order, sizeof(int), sizeof(int));
	pread(fd, &gridOffset, sizeof(off_t), sizeof(int)*2 + sizeof(int)*order*(gridSize+1) + sizeof(off_t)*cellIdx);
	for (int i = 0; i < order; i++)
		cntSize += gridDims[i][gridIdx[i]] + 1;
	lseek(fd, gridOffset, SEEK_SET);
	write(fd, &nnz, sizeof(int));
	write(fd, ptr, sizeof(int)*(nnz*order*2 + cntSize));
	write(fd, val, sizeof(double)*nnz);
	writeSize = sizeof(int)*(1 + nnz*order*2 + cntSize) + sizeof(double)*nnz;
	return writeSize;
}
off_t SubTensor :: writeSubTensorToGTF ( const int fd , int cellIdx , int * gridIdx , int * * gridDims ) { int gridSize , order , cntSize = 0 ; off_t gridOffset ; off_t writeSize ; pread ( fd , & gridSize , sizeof ( int ) , 0 ) ; pread ( fd , & order , sizeof ( int ) , sizeof ( int ) ) ; pread ( fd , & gridOffset , sizeof ( off_t ) , sizeof ( int ) * 2 + sizeof ( int ) * order * ( gridSize + 1 ) + sizeof ( off_t ) * cellIdx ) ; for ( int i = 0 ; i < order ; i ++ ) cntSize += gridDims [ i ] [ gridIdx [ i ] ] + 1 ; lseek ( fd , gridOffset , SEEK_SET ) ; write ( fd , & nnz , sizeof ( int ) ) ; write ( fd , ptr , sizeof ( int ) * ( nnz * order * 2 + cntSize ) ) ; write ( fd , val , sizeof ( double ) * nnz ) ; writeSize = sizeof ( int ) * ( 1 + nnz * order * 2 + cntSize ) + sizeof ( double ) * nnz ; return writeSize ; }
Write the subtensor (i.e., X_g[g_1, g_2, ..., g_N]) to a grid-based tensor file
Write the subtensor ( i . e . X_g [ g_1 g_2 ... g_N ] ) to a grid - based tensor file