President Carter, plagued by deepening problems elsewhere in the world, was confronted here today with a blunt warning that Mexico intends to build a more equal relationship with its long dominant neighbor to the north, the United States.

Mexican President Jose Lopez Portillo, offering a toast at a luncheon here as Carter began his two-day visit to Mexico, told the president, "It is difficult, particularly between neighbors, to maintain cordial and mutually advantageous relations in an atmosphere of mistrust or open hostility."

Making clear that Mexico intends to use its oil riches to build a more equal relationship, the Mexican president said that the United States and Mexico have not yet put their friendship "to the test, since we have yet had to decide what we are willing to make of our relationship. We can view it as a problem, or we can think of it as a conflict."

Carter did not reply directly to Lopez Portillo. Instead, he delivered a rambling, personal discourse, touching on his interest in jogging and an experience with "Montezuma's revenge" during an earlier visit to Mexico.

"My first running course was from the Palace of Fine Arts to the Majestic Hotel where I and my family were staying," Carter said. "In the midst of the performance, I discovered I was afflicted with Montezuma's revenge."

Lopez Portillo's unusually blunt remarks and the cordial but subdued reception Carter received here suggested the extent of differences between the two countries over the key issues of energy, immigration and trade.

The continuing chaos in Iran, and the slaying of U.S. Ambassador Adolph Dubs in Afghanistan, also intruded on the journey and led Carter early this morning to consider delaying it.

But the smiling president made no mention of these developments as he was greeted at Mexico City's airport by Lopez Portillo in an atmosphere of deliberate festivity.

Speaking in Spanish at the airport arrival ceremony, Carter said his talks with Lopez Portillo will include a "frank recognition of some of the important problems" between the two countries, but also an "appreciation of the common purposes and great opportunities which bind our nations together in a spirit of mutual friendship and respect.

"This is a time of dramatic and exciting change -- in Mexico, in the United States and in the relationship between us," he added. "We have much to talk about."

The relationship that the president spoke of, which has led to growing resentment here over what many Mexicans consider inferior treatment by the United States, was also clearly on Lopez Portillo's mind.

He told Carter at the airport ceremonies that he is "completely certain" that there exists between the two countries "the will to be friends, which means reciprocal respect and dignity in our dealings."

The remark about the need for "reciprocal respect and dignity" was indicative of Mexican attitudes at the beginning of Carter's 48-hour visit here.

From the airport, the two leaders drove to Lopez Portillo's office in the National Palace for the first in a series of discussions they will hold.

A major element in the Mexican government's new attitude of assertiveness toward the United States was the discovery of large-scale oil deposits here, which the United States views as a potentially stable source of supply, and which the Mexicans hope to use to win American concessions on immigration policies and trade with Mexico.

But the atmosphere for the energy talks was fouled last year when the Carter administration, at the urging of Energy Secretary James R. Schlesinger Jr., blocked an agreement by six U.S. companies to buy natural gas from Mexico. Schlesinger said the negotiated price was too high, embarrassing and angering Lopez Portillo.

On the other two key issues, Carter is under his own domestic political pressures -- to stem the flood of up to 800,000 illegal aliens, most of them from Mexico, who enter the United States each year, and to protect elements of American agriculture and industry that are threatened by Mexican exports.

Lopez Portillo's message to the president was considered unusually tough talk for a Mexican president.

"Among permanent, not casual, neighbors, surprise moves and sudden deceit or abuses are poisonous fruits that sooner or later have a reverse effect," he said. "A good neighbor policy presupposes a general climate of opinion in which respect prevails over prejudice and intelligence over sectarianism."

Lopez Portillo also made a pointed reference to Mexico's oil reserves and the change that has meant for its relations with the United States.

"Because of a nonre newable resource and the financial self-determination it provides, [Mexico] has been given the opportunity of becoming the free, secure and just nation envisioned by its great leaders of the past," he said. "Mexico has thus suddenly found itself the center of American attention -- attention that is a surprising mixture of interest, disdain and fear, much like the recurring vague fears you yourselves inspire in certain areas of our national subconscious."

Lopez Portillo's references to "surprise moves and sudden deceit" seemed clearly aimed at Schlesinger and the decision to block the gas deal.

The risk of losing Iran as a source of imported oil has underscored the importance of Mexican oil to the United States and brought renewed criticism of Schlesinger from two members of Congress who traveled here with the president.

"I very strongly disagreed with Schlesinger on the gas deal," said Sen. Lloyd Bentsen (D-Tex.). "The Mexicans don't expect the United States to fall over and play dead. They expect us to negotiate."

"Hell, yes," replied House majority leader Jim Wright (D-Tex.) when asked if he thought the administration should have approved the gas deal.

White House press secretary Jody Powell said Carter learned of the takeover of the U.S. Embassy in tehran early this morning in a telephone call from Secretary of State Cyrus Vance and decided to go ahead with the Mexican trip after receiving a detailed briefing on the situation about 6 this morning.

On the way to Mexico City, the president and his wife Rosalynn telephoned the widow of Ambassador Dubs in Washington to "express their condolences," Powell said.

Carter, who was accompanied by Vance and top White House officials, arrived in the smog-shrouded Mexican capital shortly after noon and was greeted in an atmosphere somewhat akin to a high school pep rally. The arrival area at the airport was ringed with bleachers in which sat hundreds of Mexicans, including youngsters in blue and red uniforms shaking noisemakers over their heads and waving pompoms.