In general, add acid to water. The old saying is "if you're doing what you oughter, you add the acid to water." This is primarily true when working with concentrated acids, and especially 18 M H2SO4.
You need to add the more dense liquid to the less dense liquid.
Concentrated sulfuric acid (98 percent H2SO4) releases a great deal of heat when mixed with water. Since sulfuric acid is more dense than water, adding water to 18 M H2SO4 will cause the water (now acidified) to become very hot due to the heat of hydration. If a small amount of water is added to the acid, the less dense water floats. The heat release brings about boiling and spattering.
Once H2SO4 is already diluted (e.g. 3M), adding water to the acid to make the acid even more dilute is not dangerous. 12M HCl (which is 37 percent HCl) is not as dangerous as 18M H2SO4; it already is more dilute. Nevertheless, as a point of safety make it a habit to add the acid to the water.
Adding H2SO4 to water is considerably less dangerous largely because sulfuric acid is more dense than water and will sink and mix. This will at the same time help to distribute the heat to the entire solution. Still adding a concentrated acid to water should be done with care and added slowly.