Assuming you are referring to
1) an omni-potent god,
and are looking for
2) a non-hard-determinism answer
Omniscience, a property of the Islamo/Judeo/Christian deity, is the state of knowing all. Will, or free will, is a paradox; perfect foreknowledge excludes the possibility of volition. One explanation is that although the universe is determined in advance, and major human events are determined, at an individual level there is spiritual wiggly-room in which volition is possible, and in most cases permitted (baring instances of direct intervention to preserve the major human events: consider the hardening of the heart of the Pharaoh).
The experience between the ears of humans is exempt from the usual causation of the universe because of the metaphysical (non-physical) nature of the soul, which transcends the physical world.
Given this, prayer is an act of volition possible only by those with a soul. The purposes of prayer are, in my simple understanding, grouped into four major themes:
worship/acknowledgement of the deity
investigation of the nature of the deity
request to the deity for intervention in the life of the individual
supplication to the deity to forgive the failings of the individual
The first is pleasing to the deity, and is the purpose of creation of sentient species; the tri-omni deity creates knows itself, and all things, completely, and is perfect. This deity creates minds from itself that are incomplete in their knowledge, and thereby imperfect. The deity enjoys those minds realising and being awed by the existence and nature of the deity, and seeking to be aligned to the will of the superior mind.
The second is the attempt to learn the nature/desires/will of the deity in order that behaviour can be aligned to the appeasement thereof. It is motivated by the realisation of the nature of the deity, and the obligation/gratitude of having being created.
The third is either a request of favour, or more usually a request for guidance/support in the pursuit of an activity believed to align to the nature/desires/will of the deity. This can be a request for an essentially selfish reason, to succeed in a personal endeavour, when such an endeavour is contextualised as a striving to become a less-imperfect being by delevoping those abilities or capitalising on those opportunities that the individual finds gifted to them.
The fourth is apology for deviating from the will of god (either through inappropriate behaviour or lack of appropriate behaviour. Behaviour = action, thought, attitude)
Essentially, prayer is a combination of acknowledgement of the deity, a request for instruction from the deity, a request for support in those activities that the supplicant holds dear AND believes in alignment with the will of the god, and apology for failure to act on the will of the diety/ deviation from that will.
Regular and ritualised prayer, the lip-service prayer, is a mechanism that develops this way of viewing life: gratitude for that which is, hope for that which one desires, seeking permission for all action, deference to the moral authority of the deity; the positive association formed by the repetition and social importance (thanks to deity for this food/wedding/health/sporting achievement/etc) means that in times of crisis that cognitive pattern is available as a tool for problem solving.
We turn to prayer in times of need, because we do it in times of plenty