MADRID — After centuries of emigration, Spain is attempting to cope with a huge influx of immigrants from North Africa, Latin America and Eastern Europe.

In response, the 51st San Sebastian Intl. Film Festival will unspool a key sidebar this September, designed to prepare film auds for the realities –and richness — of a multicultural society.

Dubbed “Among Friends and Neighbors,” the panorama will feature 31 pics, unveiled Thursday, from the Algeria, Morocco and Tunisia.

Though Morocco is only a 45-minute boat ride from Spain, the two countries have largely ignored each other since Spain suffered a disastrous military defeat in 1921.

That now looks set to change: Around 350,000 Moroccans have settled in Spain recently.

Pics include higher-profile items, such as Tunisian Raja Amari’s “Red Satin,” which Zeitgeist is distribbing Stateside; Moroccan Yamina Benguigui’s “Inch’Allah Sunday,” a Film Movement pickup for the U.S.; and Tunisian Mohamed Zran’s “Song for the Millennium,” which won the emerging documentary feature filmmaker award at this year’s Tribeca fest.

Many other recent pics are far less well known, such as Yamina Bachir-Chouikh’s “Rachida” and Tariq Teguia’s “The Fence,” both from Algeria, and Moroccan pics “Borders,” by Mostefa Djadjam and Faouzi Bensaidi’s “A Thousand Months.”

“Friends” also features classics stretching back to the countries’ early independence.

Many of the pics are either directed by women or turn on their repression. Emigration is another key theme.

North African filmmakers “have economic problems making films, so when they do find the money, they attempt to talk about something which is significant,” said coordinator Diego Galan.

The San Sebastian Fest, which runs Sept. 18-27, will organize two round tables and invite 20 directors from the panorama.