Being a member of a communist party in Iran can be dangerous to your health. From the Tudeh Party of Iran's website:
Written by: M. Omidvar - March 1993
ABOUT THIS PAMPHLET
The labour and communist movement in Iran is 71 years old, and this includes the 51 years of the of the Tudeh Party of Iran, the party of the Iranian working class. Since its formation the party has been the main target of attacks by internal reaction and the imperialist forces, who were and are still dominating the political life of the country in order to plunder its vast natural resources. Our party, during all these 5 decades, has been allowed to operate legally for only a few years. The party has been outlawed by various governments and Tudeh members sent to torture chambers and firing squads; yet the party has relentlessly continued its struggle, remaining loyal to the lofty ideals of peace, democracy and socialism.
Apparently, that freedom was short lived. The Tudeh Party of Iran is currently illegal and in exile:
Despite repression, the party has managed to survive. Though since the Iranian Revolution the party is officially banned in Iran and individuals found to be affiliated with communist or socialist groups risk imprisonment, active members have remained and it continues to operate as an underground political organization there.
Today, however, the party leadership is mainly based in exile, as is the new Central Committee, elected in 1992.
What if you weren't affiliated with the party, but just shared the same beliefs? That could result in your imprisonment or death, depending upon what the courts consider support. Sasan Al-e Kena was executed in 2003 for sheltering and hiding members of a communist party.
Sasan Al-e Kena’n was sentenced to death on around 17 January 2003 in connection with allegations of “sheltering and hiding members of the unauthorized Komala party in the basement of a house in Sanandaj and with moharebeh, or enmity against God".
Sasan Al-e Kena’n has reportedly been charged with the offence of moharebeh ba khoda ('enmity with God'). The charge can be invoked in cases involving "all members and supporters of a group or an organized association which have waged armed struggle against the Islamic State". Article 190 of the current Penal Code provides for the death penalty for this offence.
As for declaring yourself an atheist, that would make you guilty of apostasy. This is considered treason, and is punishable by death (men) or life in prison (women). Although, that doesn't always happen.
But one who is born as a Muslim and then apostates (murtad fitri), he is to be killed even if he repents. It is important to understand that in case a murtad fitri repents, Allãh may accept his repentance and he may be forgiven in the hereafter, but he still has to go through the punishment prescribed for his treason in this world.