Fortran 2018 with Parallel Programming 1st Edition Subrata Ray (Author) instant download
Fortran 2018 with Parallel Programming 1st Edition Subrata Ray (Author) instant download
https://textbookfull.com/product/fortran-2018-with-parallel-
programming-1st-edition-subrata-ray-author/
https://textbookfull.com/product/introduction-to-programming-
with-fortran-chivers/
https://textbookfull.com/product/introduction-to-programming-
with-fortran-ian-chivers/
https://textbookfull.com/product/modern-fortran-explained-
incorporating-fortran-2018-michael-metcalf/
https://textbookfull.com/product/modern-fortran-building-
efficient-parallel-applications-1st-edition-milan-curcic/
Modern Fortran Building efficient parallel applications
1st Edition Milan Curcic
https://textbookfull.com/product/modern-fortran-building-
efficient-parallel-applications-1st-edition-milan-curcic-2/
https://textbookfull.com/product/parallel-programming-with-co-
arrays-robert-w-numrich/
https://textbookfull.com/product/pro-tbb-c-parallel-programming-
with-threading-building-blocks-1st-edition-michael-voss/
https://textbookfull.com/product/network-and-parallel-
computing-15th-ifip-wg-10-3-international-conference-
npc-2018-muroran-japan-november-29-december-1-2018-proceedings-
feng-zhang/
https://textbookfull.com/product/parallel-programming-concepts-
and-practice-1st-edition-bertil-schmidt/
Fortran 2018 with
Parallel Programming
Fortran 2018 with
Parallel Programming
Subrata Ray
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to
publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials
or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material
reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained.
If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized
in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying,
microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.
copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400.
CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have
been granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
and
1. Preliminaries ...........................................................................................................................1
1.1 Character Set .................................................................................................................. 2
1.2 Identifiers .......................................................................................................................3
1.3 Intrinsic Data Types ......................................................................................................4
1.4 Constants and Variables...............................................................................................4
1.5 Integer Constants .......................................................................................................... 4
1.6 Real Constants ...............................................................................................................5
1.7 Double Precision Constants.........................................................................................6
1.8 Complex Constants .......................................................................................................6
1.9 Double Precision Complex Constants ........................................................................ 7
1.10 Quadruple (Quad) Precision Constants ..................................................................... 7
1.11 Logical Constants ..........................................................................................................7
1.12 Character Constants .....................................................................................................7
1.13 Literal Constants ...........................................................................................................8
1.14 Variables .........................................................................................................................8
1.15 Variable Declarations....................................................................................................8
1.16 Meaning of a Declaration.............................................................................................9
1.17 Assignment Operator ................................................................................................. 10
1.18 Named Constants........................................................................................................ 10
1.19 Keywords ..................................................................................................................... 11
1.20 Lexical Tokens ............................................................................................................. 12
1.21 Delimiters ..................................................................................................................... 12
1.22 Source Form ................................................................................................................. 13
1.23 Free Form ..................................................................................................................... 13
1.24 Continuation of Character Strings............................................................................ 15
1.25 Structure of a Program ............................................................................................... 16
1.26 IMPLICIT NONE......................................................................................................... 16
1.27 IMPLICIT ...................................................................................................................... 17
1.28 Rules of IMPLICIT ...................................................................................................... 18
1.29 Type Declarations ....................................................................................................... 18
1.30 Comments on IMPLICIT Statement ......................................................................... 19
1.31 PROGRAM Statement ................................................................................................ 19
1.32 END Statement ............................................................................................................ 19
1.33 Initialization................................................................................................................. 20
1.34 Number System ........................................................................................................... 20
1.35 Binary Numbers .......................................................................................................... 21
1.36 Octal Numbers ............................................................................................................ 21
1.37 Hexadecimal Numbers .............................................................................................. 21
1.38 Initialization Using DATA Statement ...................................................................... 21
1.39 BOZ Numbers ..............................................................................................................22
vii
viii Contents
22. Parallel Programming Using Message Passing Interface (MPI) .............................. 571
22.1 MPI Module ............................................................................................................. 571
22.2 Compilation ............................................................................................................. 571
22.3 Error Parameter of MPI Routines ......................................................................... 572
22.4 MPI Version ............................................................................................................. 572
22.5 MPI_INIT ................................................................................................................. 573
22.6 MPI_INITIALIZED ................................................................................................. 573
22.7 MPI_FINALIZE ....................................................................................................... 573
22.8 MPI Handles ............................................................................................................ 574
22.9 About This Chapter ................................................................................................ 574
22.10 Structure of a MPI Program .................................................................................. 574
22.11 MPI_COMM_RANK .............................................................................................. 575
22.12 MPI_COMM_SIZE .................................................................................................. 575
22.13 Use of Rank in Controlling the Flow of the MPI Program ............................... 576
22.14 MPI_BARRIER ........................................................................................................ 576
22.15 Basic MPI Datatype in Fortran.............................................................................. 577
22.16 Point-to-Point Communication ............................................................................. 577
22.17 Communication Modes.......................................................................................... 577
22.18 Message Sent and Received ................................................................................... 578
22.19 MPI_SEND and MPI_RECV ................................................................................. 578
22.20 MPI_SSEND............................................................................................................. 581
22.21 MPI_BSEND ............................................................................................................ 581
22.22 MPI_RSEND ............................................................................................................ 582
22.23 Deadlock .................................................................................................................. 582
22.24 Non-blocking Send and Receive ........................................................................... 583
22.25 Send Function-Naming Conventions in Blocking and Non-blocking
Forms ................................................................................................................... 585
22.26 MPI_ANY_TAG and MPI_ANY_SOURCE ......................................................... 585
22.27 REDUCTION ........................................................................................................... 586
22.28 MPI_SCAN .............................................................................................................. 592
22.29 MPI_ALLREDUCE ................................................................................................. 593
22.30 MPI_REDUCE_SCATTER_BLOCK ..................................................................... 595
22.31 MPI_REDUCE_SCATTER ..................................................................................... 596
22.32 MPI_BROADCAST ................................................................................................. 597
22.33 MPI_GATHER ......................................................................................................... 598
22.34 MPI_ALLGATHER ................................................................................................. 599
22.35 MPI_SCATTER ........................................................................................................600
22.36 MPI_SCATTERV ..................................................................................................... 601
22.37 MPI_ALLTOALL ..................................................................................................... 603
Contents xxi
Since the early days of machine computing, there has been a constant demand for larger
and faster machines. The two terms essentially mean machines with larger memory and
more speed than that of the existing available machines. During the past 70 years, there
have been dramatic changes in the fields of computer hardware and software—from
vacuum tubes to VLSI (very large scale integration) and from no operating system to very
sophisticated, time-sharing operating systems. There are three obstacles that computer
designers face while aiming to increase the speed of the computer. First, the density of the
active components within a chip cannot be increased arbitrarily. Second, with the increase
of the density of the active components within VLSI chips, heat dissipation becomes a
severe problem. Third, the speed of a signal cannot exceed the speed of light according
to the special theory of relativity proposed by Einstein. Thus, a different approach to the
problem has been thought of.
Instead of having a single processor, if several processors (each may not be very fast and
can be inexpensive) participate in parallel for computation, the speed of calculation can
be increased considerably, and in fact, using inexpensive processors controlled by special
software and hardware, the speed of a supercomputer can be achieved if hundreds of
processors work together in parallel.
This book contains an introduction to parallel computing using Fortran. Fortran supports
three types of parallel modes of computation: Coarray, OpenMP and Message Passing
Interface (MPI). All three modes of parallel computation have been discussed in this book.
In addition, the first part of the book contains a discussion on the current standard of
Fortran, namely, Fortran 2018.
The first part of the book can be used to learn the modern Fortran language even if
the reader has not yet been exposed to the earlier versions of Fortran. The book should
be read sequentially from the beginning. However, a reader who is conversant with the
earlier versions of Fortran may skip the introduction to Fortran and go directly to the new
features of the language.
As Fortran is mainly used to solve problems related to science and engineering, standard
numerical methods have been used as a vehicle to illustrate the application of the language.
However, knowledge beyond the level of elementary calculus is not required to understand
the numerical examples given in the book. The emphasis of the book is on programming
language, not on sophisticated numerical methods. The programming examples given in
the book are simple, and to keep the code readable, the codes are not always optimized. It is
expected that a reader, after proper understanding of the language, would be able to write
much more efficient codes than the codes given in the book.
Programming tips and style have been introduced at appropriate places. They serve
simply as guidelines. It is well known that every experienced programmer has his or her
own programming style.
To keep the size of the book reasonable, all available features of Fortran 2018 have
not been discussed. Moreover, only the essential components of Coarray, OpenMP and
MPI, which are required to write reasonably useful programs, have been discussed. It is
hoped that readers, after going through this book, will refer to relevant manuals and be
able to write parallel programs in Fortran to solve their numerical problems.
xxiii
xxiv Preface
The book is full of examples. Most of the examples have been tested with Intel Cor-
poration’s Fortran compiler, ifort, version 19.3, GCC gfortran version 7.3.0 and the Fortran
compiler version 6.2 of Numerical Algorithm Group (NAG). The Fortran part is based on
the draft Fortran 2018 report published on July 6, 2017. At the time of writing, these com-
pilers do not support all the proposed features of Fortran 2018, but Intel, Free Software
Foundation, Inc., and NAG will add further support for these features over time.
Subrata Ray
Acknowledgments
The author wishes to record his deep sense of gratitude to his colleagues, friends and asso-
ciates who helped him to prepare this manuscript during the various phases of this work.
The Numerical Algorithms Group Ltd., Oxford, UK, provided the author with a free
license to use their Fortran compiler. Intel Corporation allowed the author to use the trial
version of their Fortran compiler ifort. The free GCC gfortran compiler was also used.
National Council of Education, Bengal, and Institute of Business Management, NCE,
Bengal, allowed the use of their computer laboratory during the preparation of this book.
Finally, the author wishes to thank his family for their encouragement during the prepa-
ration of this manuscript.
xxv
Author
xxvii
Another Random Scribd Document
with Unrelated Content
Before the actual operation takes place, if necessary after the
anæsthetic has been given, the ear and surrounding parts should
again be carefully cleansed, and the auditory canal syringed out with
biniodide of mercury solution.
In intrameatal operations the head should be wrapped in a sterilized
towel, and a square of sterilized lint, having an aperture in the centre
so as to expose only the auricle and meatus, should be placed over
the side of the head and face. In operations on the mastoid process,
and in those involving a post-auricular incision, the head should also
be shaved for at least two or three inches beyond the region of the
ear.
Anæsthesia. Both local and general anæsthesia are used. Unless
contra-indicated for some special reason, and unless the operation is a
very trivial one, it is wiser to give a general anæsthetic. Of these,
chloroform is the most suitable in adults and infants, and the A. C. E.
mixture in children. Ether, although it may be safer, is frequently a
source of annoyance to the operator, as it tends to increase the
hæmorrhage.
In order to produce local anæsthesia two methods may be employed:
(1) The instillation of fluids into the meatus; (2) subcutaneous
injection of fluids beneath the lining membrane of the meatus and into
the surrounding parts of the auricle.
The solution usually employed is a sterilized aqueous solution of
cocaine hydrochloride in varying strengths up to 20%, to which may
be added equal parts of 1 in 1,000 adrenalin chloride solution; the
latter not only increases its analgesic properties, but also acts as a
powerful hæmostatic.
Instillation. As the auditory canal and the tympanic membrane are
lined with epithelium which is very resistant to the absorption of fluids,
complete anæsthesia is almost impossible to obtain. This method,
therefore, is practically limited to such trivial operations as the
curetting away or snaring off of granulations or polypi from the
external or middle ear. To render anæsthesia more complete, the
affected part may be finally rubbed over with a crystal of solid cocaine
hydrochloride just before the operation—is begun. On the other hand,
if the raw surface is large—for example, the wound left after a recently
performed complete mastoid operation—the cocaine employed should
not be stronger than a 5% solution in order to minimize the risk of
poisoning. Gray of Glasgow has suggested, as a more penetrating
anodyne solution, a mixture consisting of a 10% solution of cocaine
hydrochloride in equal parts of aniline oil and absolute alcohol, a
solution which he especially advocates in order to produce anæsthesia
of the tympanic membrane before doing paracentesis.
Subcutaneous injection. This is a modification of Schleich’s method,
and was first introduced by Neumann of Vienna. It consists in injecting
a very weak solution of cocaine and adrenalin chloride subcutaneously
beneath the periosteum lining the auditory canal. By this method even
the complete mastoid operation has been performed, and in certain
clinics it is used continually in the minor operations of paracentesis of
the tympanic membrane, division of intratympanic adhesions,
extraction of polypi, and ossiculectomy. A solution of beta-eucaine or
novocaine may be used in preference to cocaine, as being less
dangerous. According to Neumann, three solutions are necessary: (a)
a 1 in 2,000 solution of adrenalin chloride containing a 1% solution of
beta-eucaine; (b) a 1 in 3,000 solution of adrenalin chloride containing
a 1% solution of cocaine; (c) a 20% solution of cocaine.
The syringe for injecting the solution has a
capacity of 1 cubic centimetre, and for
convenience its needle is fixed at an obtuse
angle to the body of the syringe (Fig. 177). The
technique of the injection depends on whether
the operation is to be limited to the auditory
canal and tympanic cavity, or is to involve the
mastoid process.
If the complete mastoid operation is going to be
performed, the needle of the syringe, now filled
with the eucaine solution, is thrust through the
skin about the middle point of the mastoid
process, and a few drops of the solution are
Fig. 177. Neumann’s
injected. The needle is then forced upwards Syringe for Subcutaneous
towards the temporal ridge, at the same time Injection.
being thrust in deeply until it touches the bone,
so that a syringeful of the solution is injected beneath the periosteum.
The needle is then withdrawn and reinserted at the same point, but in
a backward direction, the solution being injected along the posterior
portion of the mastoid process; in a similar manner the solution is
injected downwards towards the tip of the mastoid. The ear being now
pulled well forward, the needle is made to pierce the fold between the
auricle and the mastoid process, just above the posterior ligament,
and is pushed inwards between the anterior border of the mastoid
process and the cartilage of the meatus, and a further syringeful of
the solution is injected. A large speculum is now inserted into the ear,
so that by pressing it against the wall of the meatus the skin, at the
termination of the cartilaginous portion, is made to project in folds.
The needle of the syringe, filled with cocaine solution, is pushed into
this fold, and a few drops of the solution injected. By degrees the
needle is still further pushed inwards, keeping it in close contact with
the bony wall so that the fluid is injected beneath the periosteum. If
the injection has been successful, a white bulging of the superior wall
of the auditory canal will be noticed. To render anæsthesia complete,
further injections may be made into the inferior and anterior walls of
the auditory canal. Finally, a pledget of cotton-wool soaked in a 20%
solution of cocaine is pushed into the tympanic cavity.
In the case of simple opening of the mastoid, subcutaneous injections
into the auditory canal are not necessary. On the other hand, if the
operation is limited to the auditory canal and tympanic cavity, the
injections into the mastoid process are not required, but a primary
injection of a small quantity of eucaine solution into the auriculo-
mastoid fold considerably diminishes the pain produced during the act
of injection into the auditory canal. Fifteen minutes should be allowed
to elapse before the operation is begun. The anæsthesia lasts about
half an hour.
Difficulties. It is by no means easy to inject fluid beneath the
periosteum of the auditory canal, owing to its close adherence to the
bone. The needle by mistake may repierce the skin at a point farther
in, so that the fluid, instead of being injected beneath the periosteum,
is injected into the auditory canal itself. In these cases anæsthesia will
not be obtained, and the operator may possibly blame the principle of
subcutaneous injection, rather than his own faulty technique.
In favour of subcutaneous injection it is urged that most of the minor
operations within the tympanic cavity, including ossiculectomy, may be
performed with the patient sitting up in the chair in the consulting
room, and further, that the patient can afterwards go home; that the
operation is rendered more easy owing to there being practically no
bleeding; and that in the case of the more severe operations, such as
opening of the mastoid antrum, the surgeon, in a case of emergency,
may make use of this method if he cannot possibly obtain the services
of an anæsthetist.
Against subcutaneous injection is the pain of the injection, which may
be so great that the patient will not submit to it, and in consequence
the proposed operation may have to be postponed.
In the case of the mastoid operation, it is difficult to believe that local
anæsthesia, however efficient, will be looked upon with favour either
by the surgeon or by the patient, except when a general anæsthetic is
absolutely contra-indicated. The discomfort produced by retraction of
the parts, the jarring caused by chiselling, and the consciousness of
what is taking place, are far more unpleasant and more of a shock to
the patient, than a general anæsthetic carefully given. Further, it is not
always possible to foretell the extent of the operation, and if repeated
injections become necessary, there is danger of eucaine or cocaine
poisoning being produced.
CHAPTER II
If the polypus be very large and tough, the snare is made to cut clean
through its pedicle as near to its attachment as possible, instead of
employing traction. The snare is then withdrawn, the polypus being
afterwards grasped and removed by means of forceps. In this latter
case it may be necessary to use a stronger snare fitted with piano
steel wire instead of the ordinary copper wire. On removal of the
polypus there may be considerable hæmorrhage. After it has ceased
the ear is syringed out and dried. The auditory canal is then inspected,
and if it is found that the growth has not been removed completely,
this can be done now by reapplication of the snare.
After final cleansing of the meatus, a strip of gauze is inserted, and
the ear protected with a pad of cotton-wool and a bandage.
After-treatment. The dressing should be removed within
twenty-four hours, and the ear cleansed by syringing. After mopping it
dry drops of rectified spirits should be instilled.
On removal of the first dressing, any polypoid tissue which remains
may be cauterized under cocaine anæsthesia by the actual cautery, or
by a bead of chromic or trichloracetic acid (see p. 348).
Further treatment consists in keeping the ear clean and dry. For the
first few days it should be syringed daily, dried, and spirit drops
instilled. As the secretion becomes less the syringing should be
diminished. If the perforation be large, instead of instilling drops,
some finely powdered boric acid may be puffed in.
Other methods of removal. These are not recommended, but
merely mentioned for the sake of completeness.
By forceps. The rough and ready method of extracting a polypus
forcibly from the ear by means of forceps, although practised formerly,
has now been discarded as being unsurgical and dangerous.
Ligation. The operation consisted in passing a snare over the polypus
and grasping it tightly as near to its base as possible. The snare was
then twisted round its axis in order to tighten the loop further and so
obliterate the blood-supply of the growth, the wire of the snare being
afterwards cut through with pliers and the snare withdrawn. After a
few days the polypus became gangrenous from want of blood-supply,
and separated from its deep attachments.
Curetting. This method, which should only be made use of in the case
of small multiple polypi within the tympanic cavity, will be considered
when discussing the treatment of granulations within the middle ear
(see p. 398).
Dangers. Hæmorrhage is seldom profuse, but if it is, it can always
be arrested by packing the meatus with cocaine and adrenalin
solution.
The chief dangers are injury to the contents of the tympanic cavity,
such as dislocation or removal of the ossicles; or subsequent
meningitis. These mishaps are usually the result of forcible extraction,
or of blindly curetting the ear after this has been done. Meningitis,
however, has been known to occur, in spite of every precaution being
taken, if, owing to caries of the tegmen tympani, the polypus has its
origin from the dura mater of the middle fossa.
Prognosis. If the polypus be single and of recent origin, the result
probably of acute inflammation of the middle ear, its removal may
cause complete recovery and cessation of the middle-ear suppuration.
In the case, however, of multiple polypi associated with chronic
middle-ear suppuration and usually signifying underlying bone disease,
recurrences may be frequent and further operations may become
necessary.
It may here be emphasized that a polypus in itself is not a disease, but
merely a symptom of disease.
After removal of a large polypus, the patient should always be kept
under observation for a day or two in case of symptoms of acute
inflammation of the mastoid process arising and necessitating further
operation.
CHAPTER III
PARACENTESIS
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com