In this paper, we consider the optimal control of the fully developed, steady, laminar, unidirectional flow of an incompressible electrically conducting fluid in a long channel of rectangular cross-section (duct). The magnetic field is generated by thin wires carrying electric current and placed along, below and/or above the channel, forming magnetic sources at the bottom and top walls of the duct. Control problem is designed to find the optimal placement of magnetic sources by using the axis coordinates of the sources as control variables to achieve the desired fluid behavior. Optimality conditions are obtained via adjoint method following discretize-then-optimize procedure. Optimization is performed by a gradient-based algorithm with bounds on the controls. The coupled system of magnetohydrodynamic (MHD) flow equations is solved by using FEM with quadratic elements. Control simulations are conducted by one, two and multiple sources for various values of the Hartmann number.