Prayer is talking to God. If God exists, prayer is no more magical thinking than you talking to someone else.
I once asked an atheist about gratitude. Who do you thank if something good happens to you that is not of your doing? He responded that when he was a cabbie, he invented someone called the Cabbies’ God, so he could show gratitude to Him for the good things God had done for him.