///For two-dimensional (2-D) and three-dimensional (3-D) magnetotelluric forward modeling problems, finite element method is used to form a linear equation Kx=b, in which K is a large sparse, banded, symmetric, conditioned and complex matrix. Its condition number is far larger than 1, and it is an ill-conditioned matrix. Solving large scale ill-conditioned linear equation is very difficult. The BICGSTAB algorithm with incomplete LU decomposition for preconditioning could be used to solve this linear equation, with advantages of fast speed, high precision and stability. In order to simulate the infinity border and meet the demand computer memory, the non-uniform grid is designed with ensuring the accuracy. In programming, the authors only store the non-zero elements of the finite element matrix. By numerical simulation of 2-D/3-D magnetotelluric responses, the authors verified the correctness of the magnetotelluric forward modeling method.