To rack one's brains

to exert one's thinking processes to the utmost for the purpose of accomplishing something; as, I racked my brains out trying to find a way to solve the problem.

See also: Rack