<< Chapter < Page Chapter >> Page >

Los códigos numéricos usualmente gastan la mayoría de su tiempo de ejecución en ciclos, así que usted no quiere nada adentro de tales ciclos que no deba estar ahí, especialmente una sentencia selectiva. Y no sólo se trata de que las sentencias selectivas entorpezcan el trabajo con instrucciones extras; también pueden forzar un orden estricto sobre las iteraciones de un ciclo. Por supuesto, no siempre pueden evitarse tales condicionales. A veces, sin embargo, la gente las pone adentro de los ciclos para procesar eventos que pudieran manejarse por separado, o incluso ignorarse.

Para hacerle retroceder unos pocos años, el siguiente código muestra un ciclo con una prueba para un valor cercano a cero:


PARAMETER (SMALL = 1.E-20) DO I=1,NIF (ABS(A(I)) .GE. SMALL) THEN B(I) = B(I) + A(I) * CENDIF ENDDO

La idea era que si el factor, A(I) , era razonablemente pequeño, no se justificaba realizar la matemática en el centro del ciclo. Dado que las operaciones de punto flotante no se colocaban en filas de espera en muchas máquinas, una comparación y un salto eran más económicos; la prueba ahorraba tiempo. En un procesador CISC más antiguo o en los primeros RISC, una comparación y un salto probablemente aún ahorren tiempo. Pero en otras arquitecturas, cuesta mucho menos realizar la matemática y evitar la prueba. Eliminar la bifurcación elimina una dependencia de control y permite que el compilador ponga en fila de espera más operaciones aritméticas. Por supuesto, la respuesta puede cambiar ligeramente si se elimina la prueba. Luego se convierte en una cuestión de cuán significativa es la diferencia. He aquí otro ejemplo donde no se requiere de una bifurcación. El bucle encuentra el valor absoluto de cada elemento en un arreglo:


DO I=1,N IF (A(I) .LT. 0.) A(I) = -A(I)ENDDO

Pero, ¿por qué realizar la prueba? En muchas máquinas, es más rápido aplicar la operación abs() a cada elemento del arreglo.

Debemos, empero, hacerle una advertencia: si está programando en C, el valor absoluto fabs() , es un llamado a subrutina. En este caso particular, le conviene más mantener el condicional adentro del ciclo. La representación de la máquina de un número de punto flotante comienza con un bit de signo. Si el bit es cero, el número es positivo. Si es 1, el número es negativo. La función de valor absoluto más rápida es aquella que simplemente aplique un "Y" al bit de signo. Véanse los macros en /usr/include/macros.h y /usr/include/math.h .

Aún en aquellos casos en que no pueda deshacerse del condicional, todavía quedan cosas que puede hacer para minimizar la pérdida de rendimiento. Primero, debemos aprender a reconocer cuáles condicionales dentro de los bucles pueden reestructurase y cuáles no. Las sentencias selectivas adentro de bucles caen en varias categorías:

  • Condicionales invariantes en el ciclo
  • Condicionales dependientes del índice del ciclo
  • Condicionales independientes del ciclo
  • Condicionales dependientes del ciclo
  • Reducciones
  • Condicionales que transfieren el control

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Cómputo de alto rendimiento. OpenStax CNX. Sep 02, 2011 Download for free at http://cnx.org/content/col11356/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Cómputo de alto rendimiento' conversation and receive update notifications?

Ask