The objective of our research is to determine whether treatment with magnesium will reduce the incidence of atrial fibrillation in patients undergoing cardiac surgery. Several small studies of magnesium have already been conducted, but these studies were small and the results conflicting. A large, well-conducted study of magnesium treatment is required to definitively determine whether magnesium is effective in preventing this common complication after surgery. In addition, our study will include patients undergoing valvular surgery, a group previously excluded from research despite the fact that they are at increased risk of atrial fibrillation.