Iraq opened its polls early on Thursday for hundreds of thousands of soldiers and police officers responsible for protecting the country's electorate, and they came under assault themselves. In all, three attacks in Baghdad, two in Mosul and another in Diyala struck near polling stations where Iraqi forces mustered to vote, a potentially ominous foreshadowing of the violence extremists have vowed to carry out in an effort to mar Sunday's pivotal election of a new Parliament. There were other problems that could also undermine the elections and their legitimacy in the eyes of Iraqis and the world. Despite months of preparations by election officials and the United Nations, irregularities were reported at polling stations across the country, with thousands of names of soldiers and police officers missing from voter rolls. 'This is an attack on our freedom to vote,' one police officer in Fallujah said, failing to find his name on the lists of eligible voters. 'Is this how the police are rewarded for their sacrifices?' The first day of voting, widely viewed as a measure of Iraq's still uncertain transition from dictatorship to democracy after the U.S. invasion seven years ago, was one of jarring contrasts. Soldiers in one part of Baghdad joyously waved their weapons and purple-stained fingers after casting their ballots, while only a few miles away, their colleagues picked through debris and bits of flesh in the gruesome aftermath of a suicide attack that struck a truckload of 27 soldiers who had just voted. At least a dozen people were killed across Baghdad -- seven of them soldiers -- and scores more were wounded, according to official counts that soldiers and police officers on the scene suggested understated the actual toll. Compared with the nihilistic bloodshed of the darkest years of the conflict here, and some of the large-scale attacks that Iraq has witnessed in recent months, the violence was small in scale. But with the U.S. military largely operating in the background, it underscored the country's precariousness ahead of the vote. In Diyala, a volatile province northeast of Baghdad, fliers and CDs scattered in the streets threatened to kill anyone who voted. The government has undertaken overwhelming security precautions, with months of planning and training with U.S. military advisers. Prime Minister Nouri Kamal al-Maliki, who faces a fierce contest to win a second term, declared a holiday from Thursday to Sunday, allowing security forces to vote early so they would be mobilized in force on election day. Far from experiencing a holiday atmosphere, though, much of the country felt under siege. Iraqis prepared for the election the way that Americans do when battening down for a hurricane. Residents cleared shops of meat, potatoes and other groceries, as prices soared. The usual congestion of traffic dissipated as a dust storm darkened the city at midday, creating a sense of gloom rather than celebration. In Baghdad and other cities, soldiers filled the streets near polling stations, as did scores of armored vehicles. Iraqi and U.S. officials have braced themselves for violence, imposing strict controls on pedestrian and vehicular traffic and cordoning off entire streets and neighborhoods. Thursday's attacks made it clear there were still gaps in security. Metal detectors stood sentry beside blast walls outside the polling stations -- most of them schools -- and yet at least half a dozen sites, they were unplugged, effectively useless. One officer claimed that the one near him was solar powered, while another said that it was safer to pat down voters by hand than to rely on machines. While the government opened a handful of polling centers to the news media on Thursday, they tried to bar correspondents and photographers from the site of the attacks, seemingly to avoid having the image of the day be bloodshed. At the scene of a suicide attack in the once upscale neighborhood of Mansour, the carnage suggested that the death toll was far higher than three killed, as the government's official account had it. As a truck overfilled with 27 army soldiers, waving and cheering, left the polling station, a suicide bomber approached on foot and blew himself up, according to a policeman at the scene. The force of the blast shattered shop windows on either side of the street and scattered debris and charred body parts. Two empty shoes lay on the ground alongside blood and shards of glass. An improvised bomb struck another school in Baghdad that is scheduled to be a polling station on Sunday but was not open for early voting. At least five people were killed and two dozen were wounded. In the northern city of Mosul, two bombs exploded at empty polling stations, without causing injuries, while another damaged the home of a candidate in an electoral alliance challenging al-Maliki's. The security forces appeared to have thwarted some attacks. In Ramadi, the provincial capital of Anbar, the police stopped a truck heavy with explosives on a bridge over the Euphrates. The driver tried to detonate his bomb, but the charge only fizzled in the truck's cab. He fled by jumping into the river, according to local security officials. The police also stopped a second tanker truck rigged with explosives in the city, killing its driver and defusing its bomb. The early voting involved nearly 1 million security officers and other voters, including prisoners and patients in hospitals. It amounted to a dress rehearsal for Sunday. Election officials said they would not announce any results before the full vote on Sunday. One effect of the years of violence in Iraq has been to create a sense of resilience and sometimes even defiance. 'The last two or three months we've been receiving warnings about violence around the elections,' a senior federal police commander said, speaking on condition of anonymity because of orders from the Ministry of the Interior. 'And we know that even after the elections, until they form a government, we have to worry about attacks.' He received a text message on his telephone about the day's first bombing, and then vowed not to let violence disrupt the election. 'Even if they hit a polling station somewhere,' he said, shortly before two suicide bombers did just that, 'we will have it open within 30 minutes and people will continue to vote.' Thursday's violence came a day after a large, coordinated wave of attacks killed at least 31 people in Baquba, the capital of Diyala. The morning after a group of police officers at one polling station began to dance elatedly: several of them had survived a suicide attack on the city's hospital. 'They promised each other to dance in front of every one of the polling stations,' Ibrahim Said, a colleague, said as he watched. 