Mathematically, a ship should be able to fire more shots if each of the cannons fire at their fastest speed, instead of waiting for everyone to be ready, but it seems that a broadside is sometimes more preferable during the age of sail, despite sacrificing the efficiency. Why is it the case? And is there any guideline on when this is preferable? (e.g. when firing from long distance, short distance, against smaller ship?)
Using Aubrey/Maturin, beefed up with "Naval life in the time of Aubrey and Maturin" type texts:
However, broadsides weren't always optimal:
"Guns firing on their own" may be a better tactic, particularly at the beginning of the battle, when what matters is the total rate of fire.
Broadsides are better when the order of the day is for concentrated fire. That usually happens later in the battle, when the idea is to do something decisive, or achieve "critical mass."
A broadside is better when the broadside is enough to sink the key enemy ship. In this case, you want to get off your broadside before he gets off his. First one to put out concentrated fire wins.
As pointed out in other answers, a broadside works best (to get the enemy to lower their heads and fire), when preparing to board an enemy ship. Also, the shock of concentrated (broadside) fire has a greater impact on enemy morale, even if "guns firing on their on their own" objectively does more damage.