We compute the prepotential of N=2 supersymmetric gauge theories in four
dimensions obtained by toroidal compactifications of gauge theories from 6
dimensions, as a function of Kahler and complex moduli of T^2. We use three
different methods to obtain this: matrix models, geometric engineering and
instanton calculus. Matrix model approach involves summing up planar diagrams
of an associated gauge theory on T^2. Geometric engineering involves
considering F-theory on elliptic threefolds, and using topological vertex to
sum up worldsheet instantons. Instanton calculus involves computation of
elliptic genera of instanton moduli spaces on R^4. We study the
compactifications of N=2* theory in detail and establish equivalence of all
these three approaches in this case. As a byproduct we geometrically engineer
theories with massive adjoint fields. As one application, we show that the
moduli space of mass deformed M5-branes wrapped on T^2 combines the Kahler and
complex moduli of T^2 and the mass parameter into the period matrix of a genus
2 curve.Comment: 90 pages, Late