1) One who is unsure whether he has prayed, must pray again. He should make a condition at the beginning of the prayer that if he has already prayed this prayer should be like a present. He must finish this prayer even if in the middle he remembers that he has already prayed. (Shulchan Aruch and Mishne Berurah 104)
2) If a man thought that he had not yet prayed, and started to pray assuming that it was an obligatory prayer, and in the middle of his prayer he remembered that he had already prayed, he must stop immediately even if he is in the middle of a blessing. (ibid)