A silent struggle of faiths is taking place inside this dynamic Indian Ocean country as Marxism increasingly pits itself against both Islam and a burning Somali nationalistic spirit.

The struggle is at once at the heart of Somalia's "scientific socialist" revolution and of the conflict now raging between the Soviet Union and Saudi Arabia over the foreign orientation of the Marxist Somali government.

It has become much more intense recently because of the Soviet decision to befriend neighboring Ethiopia - this nation's main enemy - and also because of Moscow's insistence that international Marxist solidarity take precedence over Somali nationalism. This would mean, in effect, that Somalia give up its cherished dream of reuniting all Somali-speaking peoples and bury its differences with Ethiopia in a spirit of compromise with a fellow Marxist state.

"There is enormous tension building up here and something has got to give," remarked one Western diplomat here, "but I don't know what will."

For seven years now, President Mohammed Siad Barre has skillfully and successfully blended the contradictory forces of Marxism, Islam and nationalism into a distinctly Somali ideology that has been the guiding light of his socialist revolution.

He made his country a member of the Arab League to stress its solidarity with the Islamic world, signed the first treaty of friendship and cooperation between Moscow and a black African state and vigorously pursued the Somali dream of a "greater Somaliland."

Indeed, Somalia has probably never been closer to regaining control of the territory it claims inside Ethiopia as well as of the French Territory of the Afars and Issas.

Leaders of the Somali-backed insurgency in the Ethiopian Ogaden region now have high hopes of "victory" by the end of this year, while the French territory, which becomes independent June 27, is now certain to be dominated by a pro-Somali government of Somali-speaking Issas.

Meanwhile, President Siad Barre vehemently defends the position that there need be "no contradiction" between Marxism and Islam.

"There is no chapter, not even a single word, in our Koran that opposes scientific socialism," he told a press conference here with Western and Arab journalists. "We say, 'Where is the contradiction?' . . . The contradiction was created by man only."

There is a real question, however, whether the Somali leader, for all his diplomatic skills, can continue simultaneously to placate the Soviet Union and Saudi Arabia, keep the unusual marriage between Islam and Marxism from falling apart and sustain his drive to recover what Somalia calls its "lost territories."

A visitor to this little-known East African nation of nearly 4 million people is struck by the monuments and signs throughout the country that attest to the conflicting ideological elements that make up the Somali revolution. In central Mogadishu, there is a huge modern-style mosque overlooking the city. Saudi Arabia built it as a $3 million gift to the Somali people.

At the opening here two weeks ago of the first congress of the Somali Revolutionary Youth League, however, the only portraits on the wall behind the speaker's podium were those of Siad Barre, Marx, Lenin and Engels. At a Revolutionary Rehabilitation Center for Wayward Children outside the capital, there is a poster written in English and put up by East Germans working there. It says, "The manifesto of the Communist Party - birth certificate of scientific socialism."

Yet, the strongest vibrations emanating from this young revolution are neither those of Marxism nor of Islam but Somali nationalism. Everywhere, one is reminded that this nation was cut into five pieces through the machinations of European and Ethiopian colonialism over the past century and that so far only two parts have been put together again.

Present day Somalia has reunited what was once Italian and British Somaliland. This still leaves the regions in Kenya, Ethiopia and the French Territory of the Afars and Issas where Somali-speaking people live. By its constitution and in innumberable policy declarations, Siad Barre's government has pledged itself to the reunification of all the Somali people.

Maps in government offices indicate the present borders of Somalia as "provisional boundaries." Other borders, designated as "boundaries of Somali territory," stretch far southward into Kenya to just about Mt. Kenya and westward into Ethiopia to include the town of Harrar and to within about 100 miles of Addis Abba.

This "greater Somalia" would double the size of the Somali Democratic Republic as it is today and more than double its present population to about 9 million people, according to the figures given on the standard government maps.

It is not just in the capital that all this is taken very seriously. Western correspondents visiting the small seaport of Brava at the end of a dirt track in southern Somalia found a cartoon posted on the wall of the town hall depicting the three missing portions of "greater Somalia" with a snake hissing over them and a strong Somali hand pulling it away. The words "down with colonialism" were written across the poster.

The same message is conveyed in the Somali flag, which carries a five-point star - one point for each of part of the larger nation - and on matchbox covers that show greater Somalia with a flag stretched across the Ethiopian Ogaden.

The impression of resident Arab diplomats is that nationalism still runs far deeper than Marxism in Somalia even after seven years of "scientific socialism." They say that even most of the so-called "pro-Soviet" Somalis, such as First Vice President Mohamed Samantar, are proving in their private words and emotions to be nationalists first and only very secondarily Marxists in the current Somali-Soviet falling-out over Moscow's support for the Ethiopian military regime.

This Arab perception of the basic spirit of the Somali revolution is apparently also shared by the Soviets to some extent. They have told Arab and Western diplomats that they regard the Ethiopian revolution as "more genuine" than the Somali one.

"We see the October Revolution (of the Soviet Union) all over again in what is happening in Ethiopia," one Soviet diplomat here told an Arab colleague.

In addition, the Arab impressions of President Siad Barre is also that he is first a Somali nationalist (his family came from the Ethiopian Ogaden), second a devotee of Islam and lastly a Marxist.

Where this is just wishful Arab thinking and propaganda or basically true may soon enough become apparent. For with the pressures growing daily on the Somali leader from both the Soviet Union and the conservative Arab world to choose one side or the other, to put either Marx or Mohamed first and to forego narrow Somali nationalism as the mainstay of his revolution, it appears time is running out on the delicate balance of opposites upon which Siad Barre has built his domestic and foreign tolicym.