The first thing you should do is to stop swimming immediately and after you have stopped, massage the cramped area appropriately to relieve and relax the cramped muscles, or apply a hot compress or soak in hot water if conditions allow, all with plenty of rest in the near future.