Efficient computation of coarse grid matrices is important to the overall efficiency of multigrid methods using Galerkin coarse grid approximation. A way to compute coarse grid matrices efficiently (algorithm CALRAP) with the non-zero pattern of coarse grid matrices determined by the algorithm STRURAP is discussed for the operator-independent prolongations and restrictions with boundary modifications, assuming that the discretization matrix on the finest grid is derived from a scalar partial differential equation. By means of partition of grids, the computation of coarse grid matrices near boundaries is well treated in the same way as for interior grid points, with neither introducing if-then statements nor distinguishing between interior and boundary cases in the innermost loop of algorithm CALRAP, which is expected to give an efficient computation of coarse grid matrices. Quasi-Algol descriptions of the two algorithms are developed, which can be used as predesigns for practical FORTRAN codes. A generalization of the algorithm is presented for the case that the discretization matrix derived from a set of partial differential equations, particularly the incompressible Navier-Stokes equations, discretized on a staggered grid. A quasi-Algol description of the generalization is also given.