The Mauritania government reluctantly has given its armed forces top priority in belated recognition that it is bogged down in a long battle against Algerian-backed guerillas and the outcome is in doubt

In a major government reshuffle earlier this month, President Moktar Ould Daddah put the army chief of staff in undisputed charge of national defense which formerly had been administered by a civilian super minister also entrusted with internal security.

Forcing the president's hand was the embrassing propaganda success of hit-and-run raids by guerrillas of the Polisario Front fighting the Moroccan and Mauritania takeover of the former Spanish Sahara in 1975.

Only the reliazation that the guerillas were concentrating their war ofeffort against Mauritania - rather than its richer, stronger and better defended Morroccan ally - apparently prompted the president's decision.

He had long resisted the move for fear that this sprawling arid and underpopulated country would follow the military takeover route taken by so many other African nations.

In fact, so convinced was Ould Daddah that he did not need a credible military establishment that over the past 10 years he had cut back army strength to little more than 2,200 men.

Caught unprepared, outgunned, outmanned and outmaneuvered by the Polisario guerillas in 1975, Mauritania even now is struggling to digest the estimated 10,000 to 12,000 volunteers who have since swelled the army's ranks.

The combination of a westernized, well-equipped, but ponderous Moroccan ararmy and the combtive, pursuit minded but still ill-organized Mauritanians so far has proved unable to find a way to stop the Polisario raids.

The president was reported to be furious when the Polisario staged the second raid on his capital in 13 months while he was away in Gabon early last month attending an African summit conference. The guerillas local residents say, struck on Sunday when half the police and army cadres assigned to Nouakohott were in the south of the country attending the wedding of a fellow officer.

That humiliation, combined with successive Polisario attacks in May and again in mid-July on Zouerate - the site of the ironmine that provides between 70 and 80 per cent of the country's foreign exchange earnings - pushed Mauritania further and further into Morocco's embrace.

After the first attack in May, the two allies signed aa joint defense pact. Then , after the July attack, 600 Morocco's troops - veterans of Morocco's successful springtime intervention in Zaire shoring up President Mobutu Sese Seko - were flown in a protect the mine. The French technicians were relieved.

The move was resented by many Mauritanians - including much of the army - and in fact may constitute the Polisario's biggest success to date. For Mauritanians have not forgotten that Morocco claimed that their country was rightly part of greater Morocco for the first nine years following Mauritinian independence in 1960.

The government's determination to "recover" a third of the former Spanish Sahara - has never evoked great enthusiasm among the sedentary black population living along the Senegal River valley in the Moroccans got the economically interesting two-thirds of the Spanish colony - especially rich phosphate deposits - and in any case they have no enthusiasm for fighting a war for more desert and more Moorish nomads.

Nor has the country's youth - traditionally a radical force which shoved through nationalization of the mining industries and the creation of an independent currency - completely accepted the wisdom of denying the Polisario Front's self-determination demands.

Further complicating the prosecution of the war is the suspicion of divided loyalties, especially among the warrior Rguibat tribe whose nomadic members have never paid much mind to the formal borders between Morocco, Algeria, Mauritania and the former Spanish Sahara.

Enjoying the advantage of surprise, safe haven in Algeria and at least some latent complicity among the nomads of Mauritania, the Polisario guerrillas also cash in on the fact that they correspond to a nomadic beau ideal.

"People here admire them," a diplomat said, "for their physical endurance, their courage and their audicity - all nomadic virtues - even if the guerrillas are considered to be misguided brothers led astray by the Algerians."

Whatever Mauritania's weaknesses, the situation hardly seems to justify the recent claims of Anin Sayed, the Polosario representative in Europe. He said Mauritania "offers the pathetic spectacle of a country coming apart at the seams."

In fact, the President Ould Daddah has demonstrated considerable political skill. He is in the process of consulting and the unions, women's organization and the youth group. He has allowed them to speak their minds, on condition they end up backing the government on the Sahara.

Wise enough several years ago to release his leftist political prisoners, incorporate the opposition into his government and adopt their radical anti-Western policies, now he has cleverly put trusted friends in the key internal security and information posts.

The government reshuffle, advertised as a blow for "efficiency and austerity" since it did away with 11 of 23 Cabinet posts, also satisfied those critics who insisted that the governement was not taking the war seriously enough.

Economically, despite serious infation, Mauritania's quarrrel with Algeria has prompted an unprecedented flow of petrodollars into the country. Western diplomats estimate that with Saudi Arabia in the lead, Middle Eastern investiments have amounted to 300 million since 1973, with between $1000 and $200 million accounted for in 1976 alone and a similar sum said to be coming in this year.

Saudi Arabia is widely believed to be playing for all the military expenditures which jumped 120 per cent of the budget, once tilted heavily in favor of education and economic development.

Even the May 1 attack on Zourate, in which two French citizens were killed and six others kidnapped by the Polsario raiders, has turned out to be something of a boon for Mauritania. Mauritanians moved into key mining jobs formerly held by Frenchmen, and Zourate iron ore production last month set a record.

Beyond such modern considerations lies the realization that Mauritania's fate depends very much on a seemingly far off settlement between the two main stubborn actors in the Sahara drama - King Hassan III of Morocco and President Hourari Boumedience of Algeria.

"We are but prawns," a Mauritanian businessman said, "Who with the end of colonial rule in the desert have been sucked back into our traditional habits of fighting among ourselves. We will be the real losers.