mpi/COPYING 0000644 0000000 0000000 00000104513 12262642123 011030 0 ustar 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
mpi/DESCRIPTION 0000644 0000000 0000000 00000000616 12262642123 011502 0 ustar 0000000 0000000 Name: mpi
Version: 1.2.0
Date: 2014-01-07
Author: Riccardo Corradini , Jaroslav Hajek, Carlo de Falco
Maintainer: Carlo de Falco
Title: mpi
Description: Octave bindings for basic Message Passing Interface (MPI) functions for parallel computing.
Depends: octave (>= 3.6.4)
SystemRequirements: mpi
BuildRequires: mpi
Autoload: no
License: GPLv3+
Url: http://octave.sf.net
mpi/INDEX 0000644 0000000 0000000 00000000570 12262642123 010565 0 ustar 0000000 0000000 mpi >> Message Passing Interface
Octave Wrappers for MPI functions
MPI_Barrier
MPI_Comm_Load
MPI_Comm_Test
MPI_Comm_rank
MPI_Comm_size
MPI_Finalize
MPI_Finalized
MPI_Get_processor_name
MPI_Init
MPI_Iprobe
MPI_Initialized
MPI_Probe
MPI_Recv
MPI_Send
Examples
Pi
hello2dimmat
hellocell
hellosparsemat
hellostruct
helloworld
mc_example
montecarlo mpi/NEWS 0000644 0000000 0000000 00000001447 12262642123 010476 0 ustar 0000000 0000000 Summary of changes for mpi 1.2.0:
-------------------------------------------------------------------
* Changed Makefile to allow specifying MPI compile and link options
via environment variables.
* Fixed a memory leak bug.
Summary of changes for mpi 1.1.1:
-------------------------------------------------------------------
* Package name changed.
* Patched the MPI_(I)Probe function that was incompatible with newer versions of openmpi.
* This version of the package should work with distributions of mpi other than openmpi,
not testing has been done yet, though.
Summary of changes for openmpi_ext 1.1.0:
-------------------------------------------------------------------
* Added help text and demos in all example scripts
* Code clean-up and standardization, and some bug-fixes
mpi/README 0000644 0000000 0000000 00000005336 12262642123 010660 0 ustar 0000000 0000000 CONTENTS:
--------------------
1) INSTALLATION INSTRUCTIONS
2) ORIGINAL README
--------------------
1) INSTALLATION INSTRUCTIONS
The makefile included derives all the info it needs for building the code
from running mpic++, so make sure that mpicc is in your path before running Octave
or type
putenv ("PATH", "/path/to/mpic++:${PATH}")
from within Octave.
Once this is done you should be able to install openmpi_ext from a locally dowloaded tarball
by doing:
pkg install mpi-.tar.gz
or directly from the ftp server by doing
pkg install -forge mpi
2) ORIGINAL README
Below are the contents of the original README file included with the first release
by R. Corradini, I am not sure all the info there still make sense but they are still
reported here, just in case ...
The code is general-purpose, but I would like to use it for econometrics.
So the first step will be to install the following tarball from
http://www.open-mpi.org/software/ompi/v1.3/downloads/openmpi-1.3.3.tar.bz2
possibly in a multi-core computer to run my simple examples
and configure it for instance in the following way (/home/user is your $HOME)
./configure --enable-mpirun-prefix-by-default --enable-heterogeneous --prefix=/home/user/openmpi-1.3.3/ --enable-static
and modify .bashrc in your home
OMPIBIN=`$ompi_info -path bindir -parsable | cut -d: -f3`
OMPILIB=`$ompi_info -path libdir -parsable | cut -d: -f3`
OMPISCD=`$ompi_info -path sysconfdir -parsable | cut -d: -f3`
export PATH=$OMPIBIN:$PATH
export LD_LIBRARY_PATH=:$OMPILIB:$LD_LIBRARY_PATH
unset ompi_info OMPIBIN OMPILIB OMPISCD
If you want to install it on a simple toy network, just assign a static ip address on every linux computer and set up
an ssh connection with no password (see for instance http://linuxproblem.org/art_9.html ) and then install openmpi and octave always with the same versions and with the same info on .bashrc for the same user.
After this type in a terminal mpiCC --showme
In my case I will have something like
g++ -I/home/user/openmpi-1.3.3/include -pthread -L/home/user/openmpi-1.3.3/lib -lmpi_cxx -lmpi -lopen-rte -lopen-pal -ldl -Wl,--export-dynamic -lnsl -lutil -lm -ldl
This will be useful for mkoctfile
for instance for MPI_Init.cc we shall have
mkoctfile -I/home/user/openmpi-1.3.3/include -lpthread -L/home/user/openmpi-1.3.3/lib -lmpi_cxx -lmpi -lopen-rte -lopen-pal -ldl -lnsl -lutil -lm -ldl MPI_Init.cc
The m files just contain some very simple examples
More complex examples will be provided in the next future.
See also
http://static.msi.umn.edu/tutorial/scicomp/general/MPI/content6.html
to understand the logic of MPI Derived Datatypes and how could they be easily handled by openmpi_ext package.
Bests regards
Riccardo Corradini
mpi/inst/Pi.m 0000644 0000000 0000000 00000010754 12262642123 011503 0 ustar 0000000 0000000 ## Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
## Copyright (C) 2009 Riccardo Corradini
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {[@var{result}]} = Pi ()
## Classical MPI example that computes @var{PI} by integrating arctan'(x) in [0,1].
## @var{N} [1e7] #subdivisions of the [0, 1] interval.
## @var{mod} ['s'] communication modality: (s)end (r)educe.
## @var{results} struct contains
##
## @itemize @minus
## @item @var{pi}: estimated pi value
## @item @var{err}: error
## @item @var{time}: from argument xmit to pi computed
## @end itemize
##
## To run this example, set the variables HOSTFILE and NUMBER_OF_MPI_NODES to appropriate values,
## then type the following command in your shell:
## @example
## mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave --eval 'pkg load mpi; Pi ()'
## @end example
## @seealso{hello2dimmat,helloworld,hellocell,hellosparsemat,mc_example,montecarlo,hellostruct}
## @end deftypefn
function results = Pi (N, mod)
############
## ArgChk ##
############
if (nargin < 1)
N = 1E7;
end
if (nargin < 2)
mod = 's';
end
if (nargin > 2)
print_usage (); # let all ranks complain
end
flag = 0; # code much simpler
flag = flag || ~isscalar (N) || ~isnumeric (N);
flag = flag || fix(N) ~= N || N < 1;
mod = lower (mod); mods = 'sr';
flag = flag || isempty (findstr (mod, mods));
if (flag)
print_usage (); # let them all error out
end
####################
## Results struct ##
####################
results.pi = 0;
results.err = 0;
results.time = 0;
####################################################################
## PARALLEL: initialization, include MPI_Init time in measurement ##
####################################################################
T=clock; #
############
MPI_ANY_SOURCE = -1;
MPI_Init ();
MPI_COMM_WORLD = MPI_Comm_Load ("NEWORLD");
rnk = MPI_Comm_rank (MPI_COMM_WORLD); # let it abort if it fails
siz = MPI_Comm_size (MPI_COMM_WORLD);
SLV = logical(rnk); # handy shortcuts, master is rank 0
MST = ~ SLV; # slaves are all other
#####################################################
## PARALLEL: computation (depends on rank/size) ##
#####################################################
width=1/N; lsum=0; # for i=rnk:siz:N-1
i=rnk:siz:N-1; # x=(i+0.5)*width;
x=(i+0.5)*width; # lsum=lsum+4/(1+x^2);
lsum=sum(4./(1+x.^2)); # end
#####################################
## PARALLEL: reduction and finish ##
#####################################
switch mod
case 's',
TAG=7; # Any tag would do
if SLV # All slaves send result back
MPI_Send (lsum, 0, TAG, MPI_COMM_WORLD);
else # Here at master
Sum =lsum; # save local result
for slv=1:siz-1 # collect in any order
lsum = MPI_Recv (MPI_ANY_SOURCE, TAG, MPI_COMM_WORLD);
Sum += lsum; # and accumulate
endfor # order: slv or MPI_ANY_SOURCE
endif
case 'r',
disp ("not yet implemented");
endswitch
MPI_Finalize ();
if MST
Sum = Sum/N ; # better at end: don't loose resolution
################################# # stopwatch measurement
results.time = etime(clock,T); # # but only at master after PI computed
################################# # all them started T=clock;
results.err = Sum - pi;
results.pi = Sum # ;
endif
endfunction
%!demo
%! system ("mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave -q --eval 'pkg load mpi; Pi ()'");
mpi/inst/hello2dimmat.m 0000644 0000000 0000000 00000004565 12262642123 013517 0 ustar 0000000 0000000 ## Copyright (C) 2009 Riccardo Corradini
## Copyright (C) 2012 Carlo de Falco
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} = hello2dimmat ()
## This function demonstrates sending and receiving of a 2-dimensional matrix over MPI.
## Each process in the pool will create a random 90x90 matrix and send it to process with rank 0.
## To run this example, set the variables HOSTFILE and NUMBER_OF_MPI_NODES to appropriate values,
## then type the following command in your shell:
## @example
## mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave --eval 'pkg load mpi; hello2dimmat ()'
## @end example
## @seealso{hellocell,hellosparsemat,hellostruct,helloworld,mc_example,montecarlo,Pi}
## @end deftypefn
function hello2dimmat ()
MPI_SUCCESS = 0;
MPI_Init ();
## the string NEWORLD is just a label could be whatever you want
CW = MPI_Comm_Load ("NEWORLD");
my_rank = MPI_Comm_rank (CW);
p = MPI_Comm_size (CW);
mytag = 48;
if (my_rank != 0)
## Generate a random matrix
message = rand (90, 90);
## load message
## rankvect is the vector containing the list of rank destination process
rankvect = 0;
[info] = MPI_Send (message, rankvect, mytag, CW);
else
for source = 1:p-1
disp ("We are at rank 0 that is master etc..");
[messager, info] = MPI_Recv (source, mytag, CW);
## You could also save each result and make comparisons if you don't trust MPI
disp ("Rank 0 is the master receiving ... :");
if (info == MPI_SUCCESS)
disp ('OK!');
endif
endfor
endif
MPI_Finalize ();
endfunction
%!demo
%! system ("mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave -q --eval 'pkg load mpi; hello2dimmat ()'");
mpi/inst/hellocell.m 0000644 0000000 0000000 00000004222 12262642123 013067 0 ustar 0000000 0000000 ## Copyright (C) 2009 Riccardo Corradini
## Copyright (C) 2012 Carlo de Falco
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} = hellocell ()
## This function demonstrates sending and receiving a string message over MPI.
## Each process will send a message to process with rank 0, which will then display it.
## To run this example, set the variables HOSTFILE and NUMBER_OF_MPI_NODES to appropriate values,
## then type the following command in your shell:
## @example
## mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave --eval 'pkg load mpi; hellocell ()'
## @end example
## @seealso{hello2dimmat,helloworld,hellosparsemat,hellostruct,mc_example,montecarlo,Pi}
## @end deftypefn
function hellocell ()
MPI_Init ();
## the string NEWORLD is just a label could be whatever you want
CW = MPI_Comm_Load ("NEWORLD");
my_rank = MPI_Comm_rank (CW);
p = MPI_Comm_size (CW);
## TAG is very important to identify the message
TAG = 1;
if (my_rank != 0)
message = {magic(3) 17 'fred'; ...
'AliceBettyCarolDianeEllen' 'yp' 42; ...
{1} 2 3};
rankvect = 0;
[info] = MPI_Send (message, rankvect, TAG, CW);
else
for source = 1:p-1
disp ("We are at rank 0 that is master etc..");
[messagerec, info] = MPI_Recv (source, TAG, CW);
info
messagerec
endfor
endif
MPI_Finalize ();
endfunction
%!demo
%! system ("mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave -q --eval 'pkg load mpi; hellocell ()'");
mpi/inst/hellosparsemat.m 0000644 0000000 0000000 00000005716 12262642123 014160 0 ustar 0000000 0000000 ## Copyright (C) 2009 Riccardo Corradini
## Copyright (C) 2012 Carlo de Falco
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} = hellosparsemat ()
## This function demonstrates sending and receiving a sparse matrix over MPI.
## Each process will send a a sparse matrix to process with rank 0, which will then display it.
## To run this example, set the variables HOSTFILE and NUMBER_OF_MPI_NODES to appropriate values,
## then type the following command in your shell:
## @example
## mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave --eval 'pkg load mpi; hellosparsemat ()'
## @end example
## @seealso{hello2dimmat,helloworld,hellocell,hellostruct,mc_example,montecarlo,Pi}
## @end deftypefn
function hellosparsemat ()
MPI_Init();
## the string NEWORLD is just a label could be whatever you want
CW = MPI_Comm_Load ("NEWORLD");
my_rank = MPI_Comm_rank (CW);
p = MPI_Comm_size (CW);
## tag[0] ----> type of octave_value
## tag[1] ----> array of three elements 1) num of rows 2) number of columns 3) number of non zero elements
## tag[2] ----> vector of rowindex
## tag[3] ----> vector of columnindex
## tag[4] ----> vector of non zero elements
## These tags will be generated after mytag by the MPI_Send and MPI_Recv (see source code)
mytag = 48;
## Fill the sparse matrix
M = 5; N = 5; D = 0.9;
for one_by_one = p-1:-1:1 ## work one cpu at a time to make the output readable
if (my_rank != 0)
message = sprand (M, N, D);
dest = 0;
info = MPI_Send (message, dest, mytag, CW);
printf (["on rank %d MPI_Send returned the following ", ...
"error code (0 = Success): info = %d\n"], my_rank, info)
endif
MPI_Barrier (CW);
if (my_rank == 0)
source = one_by_one;
[messager, info] = MPI_Recv (source, mytag, CW);
printf (["MPI_Recv returned the following error code (0 = Success)", ...
" while receving from rank %d : info = %d\n"], source, info);
printf ("This is the matrix received from rank %d: \n", source);
disp (full (messager))
endif
MPI_Barrier (CW);
endfor
MPI_Finalize ();
endfunction
%!demo
%! system ("mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave -q --eval 'pkg load mpi; hellosparsemat ()'");
mpi/inst/hellostruct.m 0000644 0000000 0000000 00000004174 12262642123 013502 0 ustar 0000000 0000000 ## Copyright (C) 2009 Riccardo Corradini
## Copyright (C) 2012 Carlo de Falco
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} = hellostruct ()
## This function demonstrates sending and receiving a struct over MPI.
## Each process will send a a struct to process with rank 0, which will then display it.
## To run this example, set the variables HOSTFILE and NUMBER_OF_MPI_NODES to appropriate values,
## then type the following command in your shell:
## @example
## mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave --eval 'pkg load mpi; hellostruct ()'
## @end example
## @seealso{hello2dimmat,helloworld,hellocell,hellosparsemat,mc_example,montecarlo,Pi}
## @end deftypefn
function hellostruct ()
MPI_Init ();
## the string NEWORLD is just a label could be whatever you want
CW = MPI_Comm_Load ("NEWORLD");
my_rank = MPI_Comm_rank (CW);
p = MPI_Comm_size (CW);
## TAG is very important to identify the message
TAG = 1;
if (my_rank != 0)
message = struct ("f1", {1 3; 2 4}, "f2", 25);
## Could be a vector containing the list of ranks identifiers;
rankvect = 0
info = MPI_Send (message, rankvect, TAG, CW);
else
for source = 1:p-1
disp ("We are at rank 0 that is master etc..");
[messagerec, info] = MPI_Recv (source, TAG, CW);
messagerec
endfor
endif
MPI_Finalize ();
endfunction
%!demo
%! system ("mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave -q --eval 'pkg load mpi; hellostruct ()'");
mpi/inst/helloworld.m 0000644 0000000 0000000 00000004245 12262642123 013304 0 ustar 0000000 0000000 ## Copyright (C) 2009 Riccardo Corradini
## Copyright (C) 2012 Carlo de Falco
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} = helloworld ()
## This function demonstrates sending and receiving a string message over MPI.
## Each process will send a message to process with rank 0, which will then display it.
## To run this example, set the variables HOSTFILE and NUMBER_OF_MPI_NODES to appropriate values,
## then type the following command in your shell:
## @example
## mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave --eval 'pkg load mpi; helloworld ()'
## @end example
## @seealso{hello2dimmat,hellocell,hellosparsemat,hellostruct,mc_example,montecarlo,Pi}
## @end deftypefn
function helloworld ()
MPI_Init();
## the string NEWORLD is just a label could be whatever you want
CW = MPI_Comm_Load("NEWORLD");
my_rank = MPI_Comm_rank (CW);
p = MPI_Comm_size (CW);
## Could be any number
TAG = 1;
message = "";
if (my_rank != 0)
message = sprintf ("Greetings from process: %d!", my_rank);
## rankvect is the vector containing the list of rank of destination process
rankvect = 0;
[info] = MPI_Send (message, rankvect, TAG, CW);
else
for source = 1:p-1
disp ("We are at rank 0 that is master etc..");
[message, info] = MPI_Recv (source, TAG, CW);
printf ("%s\n", message);
endfor
endif
MPI_Finalize();
endfunction
%!demo
%! system ("mpirun --hostfile $HOSTFILE -np $NUMBER_OF_MPI_NODES octave -q --eval 'pkg load mpi; helloworld ()'");
mpi/inst/mc_example.m 0000644 0000000 0000000 00000003106 12262642123 013236 0 ustar 0000000 0000000 ## Copyright (C) 2009 Riccardo Corradini
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {} = mc_example ()
## Demonstrates doing Monte Carlo with mpi.
## Does Monte Carlo on the OLS estimator. Uses montecarlo.m
## @seealso{hello2dimmat,helloworld,hellocell,hellosparsemat,Pi,montecarlo,hellostruct}
## @end deftypefn
function mc_example ()
n = 30;
theta = [1;1];
reps = 1000;
f = "olswrapper";
args = {n, theta};
outfile = "mc_output";
n_pooled = 10;
verbose = true;
## montecarlo(f, args, reps, outfile, n_pooled, false, verbose);
if not (MPI_Initialized ())
MPI_Init ();
endif
montecarlo (f, args, reps, outfile, n_pooled, verbose);
if not (MPI_Finalized)
MPI_Finalize;
endif
endfunction
function betahat = olswrapper (args)
n = args{1};
theta = args{2};
x = [ones(n,1) randn(n,1)];
y = x*theta + randn(n,1);
betahat = ols(y,x);
betahat = betahat';
endfunction
mpi/inst/montecarlo.m 0000644 0000000 0000000 00000012215 12262642123 013270 0 ustar 0000000 0000000 ## Copyright (C) 2006, 2009 Michael Creel
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {[@var{n_received}]} = @
## montecarlo (@var{f}, @var{f_args}, @var{reps}, @var{outfile}, @var{n_pooled}, @var{n_returns}, @var{usempi}, @var{verbose})
## Generate a specified number of replications of a function's
## output and write them to a user-specified output file.
##
## IMPORTANT: @var{f} should return a row vector of output from feval (f, f_args)
##
## For normal evaluation on one core, only the first 4 arguments are required.
##
## @itemize @minus
## @item Arg 1: (required) the function that generates a row vector of output
## @item Arg 2: (required) the arguments of the function, in a cell
## @item Arg 3: (required) the number of replications to generate
## @item Arg 4: (required) the output file name
## @item Arg 5 (optional) number of replications to be pooled together between writes
## @item Arg 6 (optional) verbose: 1 for on, 0 for off
## @end itemize
##
## If using MPI, you should run using ranks equal to number of cores plus 1,
## and should make sure that the core running the frontend is also the one that
## has the second rank. That way the core the frontend is on will also do work.
## @end deftypefn
function n_received = montecarlo (f, f_args, reps, outfile, n_pooled, verbose)
t0 = clock(); # initialize timing
## defaults for optional arguments
if (nargin < 6) verbose = false; endif
if (nargin < 5) n_pooled = 1; endif;
if MPI_Initialized # check if doing this parallel or serial
use_mpi = true;
CW = MPI_Comm_Load("NEWORLD");
is_node = MPI_Comm_rank(CW);
nodes = MPI_Comm_size(CW);
mytag = 48;
else
use_mpi = false;
is_node = 0;
endif
if is_node # compute nodes
more_please = 1;
while more_please
for i = 1:n_pooled
contrib = feval(f, f_args);
contribs(i,:) = contrib;
endfor
MPI_Send(contribs, 0, mytag, CW);
pause(0.05); # give time for the fronted to send a stop message, if done
# check if we're done
if (MPI_Iprobe(0, is_node, CW)) # check for ping from rank 0
junk = MPI_Recv(0, is_node, CW);
break;
endif
endwhile
else # frontend
received = 0;
done = false;
while received < reps
if use_mpi
## retrieve results from compute nodes
for i = 1:nodes-1
## compute nodes have results yet?
ready = false;
ready = MPI_Iprobe(i, mytag, CW); # check if message pending
if ready
## get it if it's there
contribs = MPI_Recv(i, mytag, CW);
need = reps - received;
received = received + n_pooled;
## truncate?
if n_pooled >= need
contribs = contribs(1:need,:);
done = true;
endif
## write to output file
FN = fopen (outfile, "a");
if (FN < 0) error ("montecarlo: couldn't open output file %s", outfile); endif
t = etime(clock(), t0);
for j = 1:rows(contribs)
fprintf(FN, "%f ", i, t, contribs(j,:));
fprintf(FN, "\n");
endfor
fclose(FN);
if verbose printf("\nContribution received from node%d. Received so far: %d\n", i, received); endif
if done
## tell compute nodes to stop loop
for j = 1:5
for i = 1:(nodes-1)
if (j==1) MPI_Send(" ",i,i,CW); endif # send out message to stop
ready = MPI_Iprobe(i, mytag, CW); # get last messages
if ready contribs = MPI_Recv(i, mytag, CW); endif
endfor
endfor
break;
endif
endif
endfor
else
for i = 1:n_pooled
contrib = feval(f, f_args);
contribs(i,:) = contrib;
endfor
need = reps - received;
received = received + n_pooled;
## truncate?
if n_pooled >= need
contribs = contribs(1:need,:);
endif
## write to output file
FN = fopen (outfile, "a");
if (FN < 0) error ("montecarlo: couldn't open output file %s", outfile); endif
t = etime(clock(), t0);
for j = 1:rows(contribs)
fprintf(FN, "%f ", 0, t, contribs(j,:));
fprintf(FN, "\n");
endfor
fclose(FN);
if verbose printf("\nContribution received from node 0. Received so far: %d\n", received); endif
endif
endwhile
endif
endfunction
mpi/src/MPI_Barrier.cc 0000644 0000000 0000000 00000005207 12262642123 013166 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
// Copyright (C) 2009 VZLU Prague
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#define NAME MPI_Barrier
/*
* ----------------------------------------------------
* Blocks until all processes in the communicator have reached this routine
* [info ] = MPI_Barrier (comm)
* ----------------------------------------------------
*/
#include "simple.h"
DEFUN_DLD (NAME, args, ,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} @var{INFO} = MPI_Barrier (@var{COMM})\n\
Block processes in the communicator @var{COMM} untill the call to this routine has been reached by all.\n\
The communicator object @var{COMM} (loaded with MPI_Comm_Load) must be specified otherwise \n\
an error occurs. \n\
@example\n\
@group\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS No error\n\
5 MPI_ERR_COMM Invalid communicator (NULL?)\n\
13 MPI_ERR_ARG Invalid argument (typically a NULL pointer?)\n\
@end group\n\
@end example\n\
@end deftypefn")
{
octave_value_list results;
int nargin = args.length ();
if (nargin != 1)
print_usage ();
else
{
if (! simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
if((args.length () != 1)
|| args(0).type_id () != simple::static_type_id ())
{
error ("MPI_Barrier: Please enter octave comunicator object");
results(0) = octave_value (-1);
}
else
{
const octave_base_value& rep = args(0).get_rep();
const simple& B = ((const simple &)rep);
MPI_Comm comm = ((const simple&) B).comunicator_value ();
if (! error_state)
{
int my_size;
int info = MPI_Barrier (comm);
results(0) = octave_value (info);
}
else
print_usage ();
}
}
return results;
}
mpi/src/MPI_Comm_Load.cc 0000644 0000000 0000000 00000003306 12262642123 013430 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
// Copyright (C) 2009 VZLU Prague
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#include "simple.h"
DEFUN_DLD(MPI_Comm_Load, args, ,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} @var{COMM} = MPI_Comm_Load (@var{DESCRIPTION})\n\
Return @var{COMM} the MPI_Communicator object whose description is @var{DESCRIPTION}, as a string.\n\
The default value will be MPI_COMM_WORLD. \n\
If @var{DESCRIPTION} is omitted, return anyway an MPI_COMM_WORLD comunicator object \n\
with no decription.\n\
For\n\
example,\n\
\n\
@example\n\
@group\n\
MPI_Init();\n\
X = MPI_Comm_Load(\"description\"); \n\
whos X\n\
MPI_Finalize();\n\
@end group\n\
@end example\n\
@end deftypefn")
{
octave_value retval;
if (args.length () != 1 || ! args (0).is_string ())
print_usage ();
else
{
if (!simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
const std::string name = args (0).string_value ();
retval = new simple (name,MPI_COMM_WORLD);
}
return retval;
}
mpi/src/MPI_Comm_Test.cc 0000644 0000000 0000000 00000003535 12262642123 013474 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
// Copyright (C) 2009 VZLU Prague
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#include "simple.h"
DEFUN_DLD(MPI_Comm_Test, args, ,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} @var{DESCRIPTION} = MPI_Comm_Test (@var{COMM})\n\
Return @var{DESCRIPTION} string description of the MPI_Communicator @var{COMM}.\n\
For\n\
example,\n\
\n\
@example\n\
@group\n\
MPI_Init();\n\
X = MPI_Comm_Load(\"description\"); \n\
whos X\n\
MPI_Comm_Test(X) \n\
@result{} \"description\"\n\
MPI_Finalize();\n\
@end group\n\
@end example\n\
@end deftypefn")
{
octave_value_list results;
if(args.length() != 1
|| args(0).type_id () != simple::static_type_id ())
{
print_usage ();
results(0) = octave_value (-1);
}
else
{
if (! simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
const octave_base_value& rep = args(0).get_rep ();
const simple& b = ((const simple &)rep);
//octave_stdout << "MPI_Comm_Test has " << b.name_value() << " output arguments.\n";
MPI_Comm res = b.comunicator_value ();
results(0) = octave_value (b.name_value ());
}
return results;
}
mpi/src/MPI_Comm_rank.cc 0000644 0000000 0000000 00000005313 12262642123 013504 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
// Copyright (C) 2009 VZLU Prague
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#define NAME MPI_Comm_rank
/*
* ----------------------------------------------------
* Determines the rank of the calling process in the communicator
* [info rank] = MPI_Comm_rank (comm)
* ----------------------------------------------------
*/
#include "simple.h"
DEFUN_DLD(NAME, args,nargout ,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} [@var{RANK} @var{INFO}] = MPI_Comm_rank (@var{COMM})\n\
Return the rank of the calling process in the specified communicator.\n\
If the comunicator object @var{COMM} (loaded with MPI_Comm_Load) is omitted \n\
an error is thrown. \n\
@example\n\
@group\n\
@var{RANK} rank of the calling process in group of communicator\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS No error\n\
5 MPI_ERR_COMM Invalid communicator (NULL?)\n\
13 MPI_ERR_ARG Invalid argument (typically a NULL pointer?)\n\
SEE ALSO: MPI_Comm_size\n\
@end group\n\
@end example\n\
@end deftypefn")
{
octave_value_list results;
int nargin = args.length ();
if (nargin != 1)
print_usage ();
else
{
if (! simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
if (args(0).type_id () == simple::static_type_id ())
{
const octave_base_value& rep = args(0).get_rep ();
const simple& B = ((const simple &)rep);
MPI_Comm comm = ((const simple&) B).comunicator_value ();
if (! error_state)
{
int my_rank;
int info = MPI_Comm_rank (comm, &my_rank);
//std::cout << my_rank << std::endl;
if (nargout > 1)
results(1) = info;
results(0) = my_rank;
}
else
print_usage ();
}
else
error ("MPI_Comm_rank: Please enter octave comunicator object");
}
return results;
}
mpi/src/MPI_Comm_size.cc 0000644 0000000 0000000 00000005465 12262642123 013533 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
// Copyright (C) 2009 VZLU Prague
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#define NAME MPI_Comm_size
/*
* ----------------------------------------------------
* Determines the size of the calling process in the communicator
* [info rank] = MPI_Comm_size (comm)
* ----------------------------------------------------
*/
#include "simple.h"
DEFUN_DLD(NAME, args,nargout ,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} [@var{RANK} @var{INFO}] = MPI_Comm_size (@var{COMM})\n\
Return the size of a communicator.\n\
The comunicator object @var{COMM} (loaded with MPI_Comm_Load) must be sepcified \n\
or otherwise an error occurs. \n\
@example\n\
@group\n\
@var{exprank} rank of the calling process in group of communicator\n\
@var{exprinfo} (int) return code\n\
0 MPI_SUCCESS No error\n\
5 MPI_ERR_COMM Invalid communicator (NULL?)\n\
13 MPI_ERR_ARG Invalid argument (typically a NULL pointer?)\n\
SEE ALSO: MPI_Comm_rank\n\
@end group\n\
@end example\n\
@end deftypefn")
{
octave_value_list results;
int nargin = args.length ();
if (nargin != 1)
print_usage ();
else
{
if (! simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
if ((args.length() != 1 )
|| args(0).type_id () != simple::static_type_id ())
{
error ("MPI_Comm_size: Please enter octave comunicator object");
results(0) = octave_value (-1);
}
else
{
const octave_base_value& rep = args(0).get_rep ();
const simple& B = ((const simple &)rep);
MPI_Comm comm = ((const simple&) B).comunicator_value ();
if (! error_state)
{
int my_size;
int info = MPI_Comm_size (comm, &my_size);
if (nargout > 1)
results(1) = info;
results(0) = my_size;
}
else
print_usage ();
}
// comm = NULL;
/* [size info] = MPI_Comm_size (comm) */
}
return results;
}
mpi/src/MPI_Finalize.cc 0000644 0000000 0000000 00000003053 12262642123 013336 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#define NAME MPI_Finalize
/*
* ----------------------------------------------------
* Terminates MPI execution environment
* info = MPI_Finalize
* ----------------------------------------------------
*/
#include "mpi.h"
#include
DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} @var{INFO} = MPI_Finalize ()\n\
Terminate the MPI execution environment.\n\
\n\
@example\n\
@group\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS No error\n\
5 MPI_ERR_COMM Invalid communicator (NULL?)\n\
13 MPI_ERR_ARG Invalid argument (typically a NULL pointer?)\n\
SEE ALSO: MPI_Init\n\
@end group\n\
@end example\n\
@end deftypefn")
{
int info = MPI_Finalize ();
return octave_value (info);
}
mpi/src/MPI_Finalized.cc 0000644 0000000 0000000 00000003335 12262642123 013505 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#define NAME MPI_Finalized
/*
* ----------------------------------------------------
* Indicates whether MPI_Finalize has completed
* [info flag] = MPI_Finalized
* ----------------------------------------------------
*/
#include "mpi.h"
#include
DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {[@var{FLAG}, @var{INFO}]} = MPI_Finalized ()\n\
Indicates whether MPI_Finalize has been executed.\n\
\n\
@example\n\
@group\n\
@var{FLAG} (int) return code\n\
0 false\n\
1 true\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS This function always returns MPI_SUCCESS\n\
SEE ALSO: MPI_Init, MPI_Finalize\n\
@end group\n\
@end example\n\
@end deftypefn")
{
octave_value_list results;
int flag;
int info = MPI_Finalized (&flag);
if (nargout > 1)
results(1) = info;
results(0) = flag != 0;
return results;
/* [flag info] = MPI_Finalized */
}
mpi/src/MPI_Get_processor_name.cc 0000644 0000000 0000000 00000003550 12262642123 015415 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
// int MPI_Get_processor_name(char *name, int *resultlen);
#include "mpi.h"
#include
DEFUN_DLD(MPI_Get_processor_name, args, nargout,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} @var{name,resultlen,INFO} = MPI_Get_processor_name ()\n\
Get the name of the processor that is using MPI.\n\
\n\
@example\n\
@group\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS No error\n\
16 MPI_ERR_OTHER Attempt was made to call MPI_Init a second time\n\
MPI_Init may only be called once in a program\n\
\n\
@end group\n\
@end example\n\
@seealso{MPI_Finalize, MPI_Initialized, MPI_Finalized}\n\
@end deftypefn")
{
int info;
int nargin = args.length ();
octave_value_list results;
if (nargin != 0)
{
print_usage ();
results(0) = octave_value (MPI_ERR_ARG);
}
else
{
std::string cpp_string;
char argv[MPI_MAX_PROCESSOR_NAME];
int resultlen = 0;
info = MPI_Get_processor_name (argv, &resultlen);
cpp_string = argv;
results(0) = cpp_string;
results(1) = resultlen;
results(2) = info;
}
return results;
}
mpi/src/MPI_Init.cc 0000644 0000000 0000000 00000004117 12262642123 012502 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
/*
* ----------------------------------------------------
* Initialize the MPI execution environment
* info = MPI_Init [ ( 'arg' [, 'arg']... ) ]
* ----------------------------------------------------
*/
#define NAME MPI_Init
#include "mpi.h" // mpi.h, oct.h
#include
DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} @var{INFO} = MPI_Init()\n\
Initialize the MPI execution environment.\n\
\n\
@example\n\
@group\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS No error\n\
16 MPI_ERR_OTHER Attempt was made to call MPI_Init a second time\n\
MPI_Init may only be called once in a program\n\
\n\
SEE ALSO: MPI_Finalize, MPI_Initialized, MPI_Finalized\n\
@end group\n\
@end example\n\
@end deftypefn")
{
int nargin = args.length();
for (int i = 0; i < nargin; i++)
{
if (! args(i).is_string ())
{
error ("MPI_Init: args must be strings");
return octave_value (MPI_ERR_ARG); // error returns nothing
}
}
string_vector argvec = args.make_argv ("MPI_Init");
char **argve= argvec.c_str_vec ();
char **argv = &argve[1];
int info = MPI_Init (&nargin, &argv);
free(argve);
return octave_value (info);
}
mpi/src/MPI_Initialized.cc 0000644 0000000 0000000 00000003356 12262642123 014050 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#define NAME MPI_Initialized
/*
* ----------------------------------------------------
* Indicates whether MPI_Initialize has been called
* [info flag] = MPI_Initialized
* ----------------------------------------------------
*/
#include "mpi.h"
#include
DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} [@var{FLAG} @var{INFO}] = MPI_Initialized\n\
Indicates whether MPI_Init has been executed.\n\
\n\
@example\n\
@group\n\
@var{FLAG} (int) return code\n\
0 false\n\
1 true\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS This function always returns MPI_SUCCESS\n\
SEE ALSO: MPI_Init, MPI_Finalize\n\
@end group\n\
@end example\n\
@end deftypefn")
{
octave_value_list results;
int flag;
int info = MPI_Initialized (&flag);
if (nargout > 1)
results (1) = info;
results(0) = octave_value (flag != 0);
return results;
/* [flag info] = MPI_Initialized */
}
mpi/src/MPI_Iprobe.cc 0000644 0000000 0000000 00000007412 12262642123 013020 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#define NAME MPI_Iprobe
/*
* ----------------------------------------------------
* Nonblocking test for a message
* [info flag stat] = MPI_Iprobe (src, tag, comm)
* ----------------------------------------------------
*/
#include "simple.h"
#include
octave_scalar_map put_MPI_Stat (MPI_Status &stat)
{
/*---------------------------------------------*/
octave_scalar_map map;
octave_value tmp = stat.MPI_SOURCE;
map.assign ("src", tmp);
tmp = stat.MPI_TAG;
map.assign ("tag", tmp );
tmp = stat.MPI_ERROR;
map.assign ("err", tmp );
int itmp;
MPI_Get_count (&stat, MPI_CHAR, &itmp);
map.assign ("cnt", itmp);
MPI_Test_cancelled (&stat, &itmp);
map.assign ("can", itmp);
return map;
}
DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} [@var{FLAG} @var{STAT} @var{INFO}] = MPI_Iprobe(@var{SRCRANK}, @var{TAG}, @var{COMM})\n\
Nonblocking test for an MPI message.\n\
@example\n\
@group\n\
\n\
@var{FLAG} int \n\
1 if the message is ready to be received\n\
0 if it is not (boolean)\n\
@var{STAT} struct object\n\
src (int) source rank for the accepted message\n\
tag (int) message tag for the accepted message\n\
err(int) error \n\
cnt (int) count\n\
can (int) cancel\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS No error\n\
13 MPI_ERR_ARG Invalid argument\n\
5 MPI_ERR_COMM Invalid communicator (null?)\n\
4 MPI_ERR_TAG Invalid tag argument (MPI_ANY_TAG, 0..MPI_TAG_UB attr)\n\
6 MPI_ERR_RANK Invalid src/dst rank (MPI_ANY_SOURCE, 0..Comm_size-1)\n\
@end group\n\
@end example\n\
\n\
@seealso{MPI_Probe, MPI_Recv, MPI documentation for examples}\n\
@end deftypefn")
{
octave_value_list results;
int nargin = args.length ();
if (nargin != 3)
print_usage ();
else
{
if (! simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
if (args(2).type_id() != simple::static_type_id ())
{
error ("MPI_Iprobe: Please enter octave comunicator object");
results = octave_value (-1);
}
else
{
const octave_base_value& rep = args(2).get_rep();
const simple& B = ((const simple &)rep);
MPI_Comm comm = ((const simple&) B).comunicator_value ();
int src = args(0).int_value();
int tag = args(1).int_value();
if (! error_state)
{
int flag;
MPI_Status stat = {0, 0, 0, 0};
int info = MPI_Iprobe (src, tag, comm, &flag, &stat);
comm = NULL;
results(0) = flag;
results(1) = put_MPI_Stat (stat);
results(2) = info;
}
else
print_usage ();
}
}
return results;
/* [flag stat info] = MPI_Iprobe (src, tag, comm) */
}
mpi/src/MPI_Op_Load.cc 0000644 0000000 0000000 00000002247 12262642123 013116 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#include "simpleop.h"
DEFUN_DLD(MPI_Op_Load, args, ,"")
{
octave_value_list retval;
if (! simpleop_type_loaded)
{
simpleop::register_type ();
simpleop_type_loaded = true;
mlock ();
}
octave_value retval;
if (args.length () != 1
|| ! args (0).is_string ())
print_usage ();
else
{
const std::string name = args (0).string_value ();
MPI_Op OP;
retval = new simpleop (name, OP);
}
return retval;
}
mpi/src/MPI_Op_Test.cc 0000644 0000000 0000000 00000002541 12262642123 013153 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#include "simpleop.h"
DEFUN_DLD(MPI_Op_Test, args, ,"")
{
if (! simpleop_type_loaded)
{
simpleop::register_type ();
simpleop_type_loaded = true;
mlock ();
}
octave_value retval;
if (args.length () != 1
|| args(0).type_id() != simpleop::static_type_id ()
|| error_state)
{
print_usage ();
retval = octave_value (-1);
}
else
{
const octave_base_value& rep = args(0).get_rep();
const simpleop& b = ((const simpleop &)rep);
octave_stdout << "simpleoptest has " << b.name_value() << " output arguments.\n";
MPI_Op res = b.operator_value();
}
return retval;
}
mpi/src/MPI_Probe.cc 0000644 0000000 0000000 00000006730 12262642123 012651 0 ustar 0000000 0000000 // Copyright (C) 2004-2007 Javier Fernández Baldomero, Mancia Anguita López
// Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#define NAME MPI_Probe
/*
* ----------------------------------------------------
* Blocking test for a message
* [info stat] = MPI_Probe (src, tag, comm)
* ----------------------------------------------------
*/
#include "simple.h"
#include
octave_scalar_map put_MPI_Stat (MPI_Status &stat)
{
/*---------------------------------------------*/
octave_scalar_map map;
octave_value tmp = stat.MPI_SOURCE;
map.assign ("src", tmp);
tmp = stat.MPI_TAG;
map.assign ("tag", tmp );
tmp = stat.MPI_ERROR;
map.assign ("err", tmp );
int itmp;
MPI_Get_count (&stat, MPI_CHAR, &itmp);
map.assign ("cnt", itmp);
MPI_Test_cancelled (&stat, &itmp);
map.assign ("can", itmp);
return map;
}
DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} [@var{STAT} @var{INFO}] = MPI_Probe(@var{SRCRANK}, @var{TAG}, @var{COMM})\n \
Blocking test for a message.\n\
@example\n\
@group\n\
\n\
@var{STAT} struct object\n\
src (int) source rank for the accepted message\n\
tag (int) message tag for the accepted message\n\
err(int) error \n\
cnt (int) count\n\
can (int) cancel\n\
@var{INFO} (int) return code\n\
0 MPI_SUCCESS No error\n\
13 MPI_ERR_ARG Invalid argument\n\
5 MPI_ERR_COMM Invalid communicator (null?)\n\
4 MPI_ERR_TAG Invalid tag argument (MPI_ANY_TAG, 0..MPI_TAG_UB attr)\n\
6 MPI_ERR_RANK Invalid src/dst rank (MPI_ANY_SOURCE, 0..Comm_size-1)\n\
@end group\n\
@end example\n\
\n\
@seealso{MPI_Iprobe, MPI_Recv, and MPI documentation for C examples}\n\
@end deftypefn")
{
octave_value_list results;
int nargin = args.length ();
if (nargin != 3)
print_usage ();
else
{
if (!simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
if (args(2).type_id () == simple::static_type_id ())
{
const octave_base_value& rep = args(2).get_rep ();
const simple& B = ((const simple &)rep);
MPI_Comm comm = ((const simple&) B).comunicator_value ();
int src = args(0).int_value ();
int tag = args(1).int_value ();
if (! error_state)
{
MPI_Status stat = {0, 0, 0, 0};
int info = MPI_Probe (src, tag, comm, &stat);
comm= NULL;
results(0) = put_MPI_Stat (stat);
results(1) = info;
}
}
else
{
print_usage ();
results = octave_value (-1);
}
return results;
/* [ stat info ] = MPI_Probe (src, tag, comm) */
}
}
mpi/src/MPI_Recv.cc 0000644 0000000 0000000 00000055162 12262642123 012504 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
// Copyright (C) 2009 VZLU Prague
// Copyright (C) 2012, 2013, 2014 Carlo de Falco
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#include "simple.h"
#include // avoid errmsg "cell -- incomplete datatype"
#include // avoid errmsg "Oct.map -- invalid use undef type"
// forward declarations
int
recv_class (MPI_Comm comm, octave_value &ov, int source, int mytag);
int
recv_cell (MPI_Comm comm, octave_value &ov, int source, int mytag);
int
recv_struct (MPI_Comm comm, octave_value &ov, int source, int mytag);
int
recv_string (MPI_Comm comm, octave_value &ov, int source, int mytag);
int
recv_range (MPI_Comm comm, octave_value &ov, int source, int mytag);
template
int
recv_vec (MPI_Comm comm, AnyElem &LBNDA, int nitem, MPI_Datatype TRCV,
int source, int mytag);
int
recv_matrix (bool is_complex, MPI_Datatype TRcv, MPI_Comm comm,
octave_value &ov, int source, int mytag);
int
recv_sp_mat (bool is_complex, MPI_Datatype TRcv, MPI_Comm comm,
octave_value &ov, int source, int mytag);
template
int recv_scalar (MPI_Datatype TRcv, MPI_Comm comm, Any *d, int source,
int mytag);
template
int
recv_scalar (MPI_Datatype TRcv, MPI_Comm comm, std::complex *d,
int source, int mytag);
int
recv_range (MPI_Comm comm, octave_value &ov, int source, int mytag)
{
// Send/Recv as base, limit, incr, nelem
// just 3 doubles + 1 int
// octave_range (double base, double limit, double inc)
OCTAVE_LOCAL_BUFFER(int, tanktag, 3);
OCTAVE_LOCAL_BUFFER(double, d, 2);
MPI_Status stat;
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
// first receive
int info = MPI_Recv (d, 3, MPI_DOUBLE, source, tanktag[1], comm, &stat);
if (info == MPI_SUCCESS)
{
int nelem = 0;
info = MPI_Recv
(&nelem, 1, MPI_INT, source, tanktag[2], comm, &stat);
if (info == MPI_SUCCESS)
{
Range r (d[0], d[2], nelem);
ov = r;
}
}
return info;
}
// This will get the fortran_vec vector for Any type Octave can handle
template
int
recv_vec (MPI_Comm comm, AnyElem &LBNDA, int nitem, MPI_Datatype TRCV,
int source, int mytag)
{
MPI_Status stat;
int info = MPI_Recv (LBNDA, nitem, TRCV, source, mytag, comm, &stat);
return (info);
}
// template specialization for complex case
template
int
recv_scalar (MPI_Datatype TRcv, MPI_Comm comm, std::complex &d,
int source, int mytag)
{
int info;
MPI_Status stat;
OCTAVE_LOCAL_BUFFER(int, tanktag, 2);
tanktag[0] = mytag;
tanktag[1] = mytag+1;
OCTAVE_LOCAL_BUFFER(std::complex, Deco, 2);
Deco[0] = real (d);
Deco[1] = imag (d);
info = MPI_Recv (&Deco, 2, TRcv, source, tanktag[1], comm, &stat);
return info;
}
template
int
recv_scalar (MPI_Datatype TRcv, MPI_Comm comm, Any &d, int source, int mytag)
{
// it's just a value directly MPI_Recv it
OCTAVE_LOCAL_BUFFER(int, tanktag, 2);
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
int info;
MPI_Status stat;
info = MPI_Recv (&d, 1, TRcv, source, tanktag[1], comm, &stat);
return info;
}
int
recv_string (MPI_Comm comm, octave_value &ov, int source, int mytag)
{
// it's just a string value directly MPI_Recv it
std::string cpp_string;
OCTAVE_LOCAL_BUFFER(int, tanktag, 2);
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
int info, nitem;
MPI_Status stat;
info = MPI_Recv (&nitem, 1, MPI_INT, source, tanktag[1], comm, &stat);
OCTAVE_LOCAL_BUFFER(char, mess, nitem + 1);
if (info == MPI_SUCCESS)
{
info = MPI_Recv (mess, nitem + 1, MPI_CHAR, source, tanktag[2], comm, &stat);
if (info == MPI_SUCCESS)
{
cpp_string = mess;
ov = cpp_string;
}
}
return info;
}
int
recv_matrix (bool is_complex, MPI_Datatype TRCV, const MPI_Comm comm,
octave_value &ov, int source, int mytag)
{
OCTAVE_LOCAL_BUFFER(int, tanktag, 6);
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
tanktag[3] = mytag + 3;
tanktag[4] = mytag + 4;
tanktag[5] = mytag + 5;
int info;
int nitem, nd;
MPI_Status stat;
dim_vector dv;
// Receive the number of elements
info = MPI_Recv (&nitem, 1, MPI_INT, source, tanktag[1], comm, &stat);
if (info != MPI_SUCCESS) return info;
// Receive the number of dimensions
info = MPI_Recv (&nd, 1, MPI_INT, source, tanktag[2], comm, &stat);
if (info != MPI_SUCCESS) return info;
// Create a buffer to store the dim_vector elements and receive data
dv.resize (nd);
OCTAVE_LOCAL_BUFFER(int, dimV, nd);
info = MPI_Recv (dimV, nd, MPI_INT, source, tanktag[3], comm, &stat);
if (info != MPI_SUCCESS) return info;
// Now reverse the content of int vector into dim vector
for (octave_idx_type i = 0; i < nd; i++)
dv(i) = dimV[i] ;
if (is_complex)
{
// FIXME : it should be easy to avoid the extra memory allocation and copying
#define __MAKE_CMPLX_TYPE_BRANCH__(TMPI, T1, A1) \
if (TRCV == TMPI) \
{ \
OCTAVE_LOCAL_BUFFER(T1, LBNDA1, nitem); \
info = recv_vec (comm, LBNDA1, nitem, TRCV, \
source, tanktag[4]); \
if (info == MPI_SUCCESS) \
{ \
A1 myNDA (dv); \
OCTAVE_LOCAL_BUFFER(T1, LBNDA2, nitem); \
info = recv_vec (comm, LBNDA2, nitem, TRCV, \
source, tanktag[5]); \
if (info == MPI_SUCCESS) \
{ \
for (octave_idx_type i = 0; i < nitem; i++) \
myNDA(i) = real (LBNDA1[i]) + imag (LBNDA2[i]); \
\
ov = myNDA; \
} \
} \
}
__MAKE_CMPLX_TYPE_BRANCH__(MPI_DOUBLE, double, ComplexNDArray)
else
__MAKE_CMPLX_TYPE_BRANCH__(MPI_FLOAT, float, FloatComplexNDArray)
#undef __MAKE_CMPLX_TYPE_BRANCH__
}
else
{
// FIXME : it should be easy to avoid the extra memory allocation and copying
#define __MAKE_TYPE_BRANCH__(TMPI, T1, A1) \
if (TRCV == TMPI) \
{ \
A1 myNDA (dv); \
OCTAVE_LOCAL_BUFFER(T1, LBNDA, nitem); \
info = recv_vec \
(comm, LBNDA, nitem, TRCV, source, tanktag[4]); \
if (info == MPI_SUCCESS) \
{ \
T1 *myNDA_ptr = myNDA.fortran_vec (); \
for (octave_idx_type i = 0; i < nitem; i++) \
myNDA_ptr[i] = LBNDA[i]; \
ov = myNDA; \
} \
}
__MAKE_TYPE_BRANCH__(MPI_DOUBLE, double, NDArray)
else
__MAKE_TYPE_BRANCH__(MPI_INT, bool, boolNDArray)
else
__MAKE_TYPE_BRANCH__(MPI_FLOAT, float, FloatNDArray)
else
__MAKE_TYPE_BRANCH__(MPI_BYTE, octave_int8, int8NDArray)
else
__MAKE_TYPE_BRANCH__(MPI_SHORT, octave_int16, int16NDArray)
else
__MAKE_TYPE_BRANCH__(MPI_INT, octave_int32, int32NDArray)
else
__MAKE_TYPE_BRANCH__(MPI_LONG_LONG, octave_int64, int64NDArray)
else
__MAKE_TYPE_BRANCH__(MPI_UNSIGNED_CHAR, octave_uint8, uint8NDArray)
else
__MAKE_TYPE_BRANCH__(MPI_UNSIGNED_SHORT, octave_uint16, uint16NDArray)
else
__MAKE_TYPE_BRANCH__(MPI_UNSIGNED, octave_uint32, uint32NDArray)
else
__MAKE_TYPE_BRANCH__(MPI_UNSIGNED_LONG_LONG, octave_uint64,
uint64NDArray)
#undef __MAKE_TYPE_BRANCH__
}
return info;
}
int
recv_sp_mat (bool is_complex, MPI_Datatype TRcv, MPI_Comm comm,
octave_value &ov, int source, int mytag)
{
int info;
OCTAVE_LOCAL_BUFFER(int, tanktag,6);
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
tanktag[3] = mytag + 3;
tanktag[4] = mytag + 4;
tanktag[5] = mytag + 5;
MPI_Status stat;
OCTAVE_LOCAL_BUFFER(int, s, 3);
// receive the shape and capacity of
// the matrix in an int vector named s
info = MPI_Recv (s, 3, MPI_INT, source, tanktag[1], comm, &stat);
if (info != MPI_SUCCESS)
return info;
// Receive row and column index
OCTAVE_LOCAL_BUFFER(int, sridx, s[2]);
OCTAVE_LOCAL_BUFFER(int, scidx, s[1] + 1);
info = MPI_Recv (sridx, s[2], MPI_INT, source, tanktag[2], comm, &stat);
if (info != MPI_SUCCESS)
return info;
// receive the vector with column indexes
info = MPI_Recv (scidx, s[1] + 1, MPI_INT, source, tanktag[3], comm, &stat);
if (info != MPI_SUCCESS)
return info;
// Now we have a different vector of non zero elements according to datatype
#define __MAKE_TYPE_BRANCH__(TMPI, T1, A1) \
if (TRcv == TMPI) \
{ \
A1 m (s[0], s[1], s[2]); \
OCTAVE_LOCAL_BUFFER(T1, LBNDA, s[2]); \
info = recv_vec (comm, LBNDA, s[2], TRcv, source, tanktag[4]); \
if (info != MPI_SUCCESS) return info; \
\
for (octave_idx_type i = 0; i < s[1]+1; i++) \
m.cidx(i) = scidx[i]; \
for (octave_idx_type i = 0; i < s[2]; i++) \
{ \
m.ridx(i) = sridx[i]; \
m.data(i) = LBNDA[i]; \
} \
ov = m; \
}
if (is_complex)
{
if (TRcv == MPI_DOUBLE)
{
TRcv = MPI_DOUBLE;
SparseComplexMatrix m (s[0], s[1], s[2]);
OCTAVE_LOCAL_BUFFER(double, LBNDA1, s[2]);
OCTAVE_LOCAL_BUFFER(double, LBNDA2, s[2]);
info = recv_vec (comm, LBNDA1, s[2], TRcv, source, tanktag[4]);
if (info != MPI_SUCCESS) return info;
info = recv_vec (comm, LBNDA2, s[2], TRcv, source, tanktag[5]);
if (info != MPI_SUCCESS) return info;
for (octave_idx_type i = 0; i < s[1] + 1; i++)
m.cidx(i) = scidx[i];
for (octave_idx_type i = 0; i < s[2]; i++)
{
m.ridx(i) = sridx[i];
m.data(i) = real (LBNDA1[i]) + imag (LBNDA2[i]);
}
ov = m;
}
}
else
{
__MAKE_TYPE_BRANCH__(MPI_INT, bool, SparseBoolMatrix)
else
__MAKE_TYPE_BRANCH__(MPI_DOUBLE, double, SparseMatrix)
}
#undef __MAKE_TYPE_BRANCH__
return info;
}
int
recv_cell (MPI_Comm comm, octave_value &ov, int source, int mytag)
{
OCTAVE_LOCAL_BUFFER(int, tanktag, 5);
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
tanktag[3] = mytag + 3;
tanktag[4] = mytag + 4;
int info;
int nitem,nd;
MPI_Status stat;
dim_vector dv;
// nitem is the total number of elements
info = MPI_Recv ((&nitem), 1, MPI_INT, source, tanktag[1], comm, &stat);
if (info != MPI_SUCCESS) return info;
// ndims is number of dimensions
info = MPI_Recv (&nd, 1, MPI_INT, source, tanktag[2], comm, &stat);
if (info != MPI_SUCCESS) return info;
// Now create contiguous datatype for dim vector
dv.resize (nd);
OCTAVE_LOCAL_BUFFER(int, dimV, nd);
MPI_Datatype dimvec;
MPI_Type_contiguous (nd, MPI_INT, &dimvec);
MPI_Type_commit (&dimvec);
info = MPI_Recv (dimV, 1, dimvec, source, tanktag[3], comm, &stat);
if (info != MPI_SUCCESS) return info;
// Now reverse the content of int vector into dim vector
for (octave_idx_type i=0; i::elem(i) = celem;
}
ov = oc;
MPI_Type_free (&dimvec);
return info;
}
int
recv_struct (MPI_Comm comm, octave_value &ov, int source, int mytag)
{
octave_scalar_map om;
int n; // map.fields ();
OCTAVE_LOCAL_BUFFER(int, tanktag, 2);
tanktag[0] = mytag; // t_id
tanktag[1] = mytag + 1; // n
int tagcap = mytag + 2;
int ntagkey = mytag + 3; // string
int ctag = mytag + 4; // cell
int info;
MPI_Status stat;
info = MPI_Recv (&n, 1,MPI_INT, source, tanktag[1], comm, &stat);
int scap;
for (int i = 0; i < n; i++)
{
/* nkeys: foreach, get key */
octave_value ov_string;
ntagkey = ntagkey + 3;
info = recv_class (comm, ov_string, source, ntagkey);
std::string key = ov_string.string_value ();
if (info != MPI_SUCCESS) return info;
/* all elements on this fname */
octave_value conts;
// Receives capacity
info = MPI_Recv (&scap, 1, MPI_INT, source, tagcap, comm, &stat);
tagcap = tagcap + 1;
ctag = ctag + scap;
info = recv_class (comm, conts, source, ctag);
if (! conts.is_cell ()) return MPI_ERR_UNKNOWN;
om.assign (key, conts.cell_value ());
}
if (n != om.nfields ())
{
error ("MPI_Recv: inconsistent map length");
return MPI_ERR_UNKNOWN;
}
ov=om;
return MPI_SUCCESS;
}
int
recv_class (MPI_Comm comm, octave_value &ov, int source, int mytag )
{
/*------------------------------------*/
/* varname-strlength 1st, dims[ndim] */
/* and then appropriate specific info */
int t_id;
MPI_Status status;
int info = MPI_Recv (&t_id, 1, MPI_INT, source, mytag, comm, &status);
static string_vector pattern = octave_value_typeinfo::installed_type_names ();
const std::string tstring = pattern (t_id);
if (tstring == "cell")
return (recv_cell (comm, ov, source, mytag));
if (tstring == "struct")
return (recv_struct (comm, ov, source, mytag));
if (tstring == "scalar")
{
double d = 0;
MPI_Datatype TRcv = MPI_DOUBLE;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "bool")
{
bool b;
MPI_Datatype TRcv = MPI_INT;
info = recv_scalar (TRcv,comm, b,source,mytag);
ov = b;
return info;
}
if (tstring == "int8 scalar")
{
octave_int8 d;
MPI_Datatype TRcv = MPI_BYTE;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov=d ;
return info;
}
if (tstring == "int16 scalar")
{
octave_int16 d;
MPI_Datatype TRcv = MPI_SHORT;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "int32 scalar")
{
octave_int32 d;
MPI_Datatype TRcv = MPI_INT;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "int64 scalar")
{
octave_int64 d;
MPI_Datatype TRcv = MPI_LONG_LONG;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "uint8 scalar")
{
octave_uint8 d;
MPI_Datatype TRcv = MPI_UNSIGNED_CHAR;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "uint16 scalar")
{
octave_uint16 d;
MPI_Datatype TRcv = MPI_UNSIGNED_SHORT;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "uint32 scalar")
{
octave_uint32 d;
MPI_Datatype TRcv = MPI_UNSIGNED;
info = recv_scalar (TRcv,comm, d,source,mytag);
ov = d;
return info;
}
if (tstring == "uint64 scalar")
{
octave_uint64 d;
MPI_Datatype TRcv = MPI_UNSIGNED_LONG_LONG;
info = recv_scalar (TRcv,comm, d,source,mytag);
ov = d;
return info;
}
if (tstring == "float scalar")
{
float d;
MPI_Datatype TRcv = MPI_FLOAT;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "complex scalar")
{
std::complex d;
MPI_Datatype TRcv = MPI_DOUBLE;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "float complex scalar")
{
std::complex d;
MPI_Datatype TRcv = MPI_FLOAT;
info = recv_scalar (TRcv, comm, d, source, mytag);
ov = d;
return info;
}
if (tstring == "string")
return (recv_string (comm, ov, source, mytag));
if (tstring == "sq_string")
return (recv_string (comm, ov, source, mytag));
if (tstring == "range")
return (recv_range (comm, ov, source, mytag));
if (tstring == "matrix")
return (recv_matrix (false, MPI_DOUBLE, comm, ov, source, mytag));
if (tstring == "complex matrix")
return (recv_matrix (true, MPI_DOUBLE, comm, ov, source, mytag));
if (tstring == "bool matrix")
return (recv_matrix (false, MPI_INT, comm, ov, source, mytag));
if (tstring == "int8 matrix")
return (recv_matrix (false, MPI_BYTE, comm, ov, source, mytag));
if (tstring == "int16 matrix")
return (recv_matrix (false, MPI_SHORT, comm, ov, source, mytag));
if (tstring == "int32 matrix")
return (recv_matrix (false, MPI_INT, comm, ov, source, mytag));
if (tstring == "int64 matrix")
return (recv_matrix (false, MPI_LONG_LONG, comm, ov, source, mytag));
if (tstring == "uint8 matrix")
return (recv_matrix (false, MPI_UNSIGNED_CHAR, comm, ov, source, mytag));
if (tstring == "uint16 matrix")
return (recv_matrix (false, MPI_UNSIGNED_SHORT, comm, ov, source, mytag));
if (tstring == "uint32 matrix")
return (recv_matrix (false, MPI_UNSIGNED, comm, ov, source, mytag));
if (tstring == "uint64 matrix")
return (recv_matrix (false, MPI_UNSIGNED_LONG_LONG, comm, ov, source, mytag));
if (tstring == "float matrix")
return (recv_matrix (false, MPI_FLOAT,comm, ov,source,mytag));
if (tstring == "float complex matrix")
return (recv_matrix (true, MPI_FLOAT, comm, ov, source, mytag));
if (tstring == "sparse matrix")
return (recv_sp_mat (false, MPI_DOUBLE, comm, ov, source, mytag));
if (tstring == "sparse complex matrix")
return (recv_sp_mat (true, MPI_DOUBLE, comm, ov, source, mytag));
if (tstring == "")
{
error ("MPI_Recv: unknown class");
return MPI_ERR_UNKNOWN;
}
else
{
error ("MPI_Recv: unsupported class %s", ov.type_name ().c_str ());
return MPI_ERR_UNKNOWN;
}
}
DEFUN_DLD(MPI_Recv, args, nargout,"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} [@var{VALUE} @var{INFO}] = \
MPI_Recv(@var{SOURCE},@var{TAG},@var{COMM})\n\
Receive an MPI message containing an Octave variable and extract its value.\n\
The Octave variable being received is returned as @var{VALUE},\n\
while @var{INFO} is an integer indicating success or failure.\n\
@example\n\
@group\n\
@var{SOURCE} must be an integer indicating source processes \n\
@var{TAG} must be an integer to identify the message by openmpi \n\
@var{COMM} must be an octave communicator object created by \
MPI_Comm_Load function \n\
@end group\n\
@end example\n\
@seealso{MPI_Comm_Load,MPI_Init,MPI_Finalize,MPI_Send}\n\
@end deftypefn")
{
octave_value_list retval;
int nargin = args.length ();
if (nargin != 3)
print_usage ();
else
{
int source = args(0).int_value ();
int mytag = args(1).int_value ();
if (! error_state)
{
if (! simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
if (args(2).type_id () == simple::static_type_id ())
{
const octave_base_value& rep = args(2).get_rep ();
const simple& B = ((const simple &)rep);
MPI_Comm comm = ((const simple&) B).comunicator_value ();
octave_value result;
int info = recv_class (comm, result, source, mytag);
comm = NULL;
retval(1) = octave_value (info);
retval(0) = result;
}
else
{
error ("Please enter octave comunicator object!");
retval = octave_value (-1);
}
}
}
return retval;
}
mpi/src/MPI_Send.cc 0000644 0000000 0000000 00000077460 12262642123 012503 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
// Copyright (C) 2009 VZLU Prague
// Copyright (C) 2012, 2013, 2014 Carlo de Falco
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#include "simple.h"
#include // avoid errmsg "cell -- incomplete datatype"
#include // avoid errmsg "Oct.map -- invalid use undef type"
// forward declarations ordered by datatype
int
send_class (MPI_Comm comm, const octave_value &ov,
const Array &rankrec, int mytag);
int
send_string (int t_id, MPI_Comm comm, std::string oi8,
const Array &rankrec, int mytag);
int
send_cell (int t_id, MPI_Comm comm, Cell cell,
const Array &rankrec, int mytag);
int
send_struct (int t_id, MPI_Comm comm, octave_map map,
const Array &rankrec, int mytag);
template
int
send_scalar (int t_id, MPI_Datatype TSnd, MPI_Comm comm, std::complex d,
const Array &rankrec, int mytag);
template
int
send_scalar (int t_id, MPI_Datatype TSnd, MPI_Comm comm, Any d,
const Array &rankrec, int mytag);
int
send_range (int t_id, MPI_Comm comm, Range range,
const Array &rankrec, int mytag);
int
send_matrix (int t_id, MPI_Datatype TSnd, MPI_Comm comm,
const octave_value &myOv, const Array &rankrec,
int mytag);
int
send_sp_mat (int t_id, MPI_Datatype TSnd, MPI_Comm comm,
const octave_value &MyOv, const Array &rankrec,
int mytag);
// template specialization for complex case
template
int
send_scalar (int t_id, MPI_Datatype TSnd, MPI_Comm comm, std::complex d,
const Array &rankrec, int mytag)
{
OCTAVE_LOCAL_BUFFER(int, tanktag, 2);
OCTAVE_LOCAL_BUFFER(std::complex, Deco, 2);
int info;
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
Deco[0] = real (d);
Deco[1] = imag (d);
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec ();
for (octave_idx_type i = 0; i < rankrec.nelem (); i++)
{
info = MPI_Send
(&t_id, 1, MPI_INT, rankrec_ptr[i], tanktag[0], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(&Deco, 2, TSnd, rankrec_ptr[i], tanktag[1], comm);
if (info != MPI_SUCCESS) return info;
}
return (info);
}
template
int
send_scalar (int t_id, MPI_Datatype TSnd, MPI_Comm comm, Any d,
const Array &rankrec, int mytag)
{
OCTAVE_LOCAL_BUFFER(int,tanktag,2);
int info;
tanktag[0] = mytag;
tanktag[1] = mytag+1;
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec ();
for (octave_idx_type i = 0; i< rankrec.nelem(); i++)
{
info = MPI_Send
(&t_id, 1, MPI_INT, rankrec_ptr[i], tanktag[0], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(&d, 1, TSnd, rankrec_ptr[i], tanktag[1], comm);
if (info != MPI_SUCCESS) return info;
}
return (info);
}
int
send_range (int t_id, MPI_Comm comm, Range range,
const Array &rankrec, int mytag)
{
OCTAVE_LOCAL_BUFFER(int, tanktag, 3);
OCTAVE_LOCAL_BUFFER(double, d, 3);
// send as: base, limit, incr, nelem
// just 3 doubles + 1 int
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
// Range (double b, double l, double i)
d[0]= range.base ();
d[1]= range.limit ();
d[2]= range.inc ();
int nele = range.nelem ();
int info = MPI_SUCCESS;
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec ();
for (octave_idx_type i = 0; i< rankrec.nelem (); i++)
{
info = MPI_Send
(&t_id, 1, MPI_INT, rankrec_ptr[i], tanktag[0], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(d, 2, MPI_DOUBLE, rankrec_ptr[i], tanktag[1], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(&nele, 1, MPI_INT, rankrec_ptr[i], tanktag[2], comm);
if (info != MPI_SUCCESS) return info;
}
return (info);
}
int
send_matrix (int t_id, MPI_Datatype TSnd, MPI_Comm comm,
const octave_value &myOv, const Array &rankrec,
int mytag)
{
OCTAVE_LOCAL_BUFFER(int, tanktag, 6);
// real branch:
// OCTAVE_LOCAL_BUFFER(int, dimV, nd);
// complex branch:
// OCTAVE_LOCAL_BUFFER(T3, LBNDA1, nitem);
// OCTAVE_LOCAL_BUFFER(T3, LBNDA2, nitem);
int info;
int nitem;
dim_vector dv;
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
tanktag[3] = mytag + 3;
tanktag[4] = mytag + 4;
tanktag[5] = mytag + 5;
int nd;
#define __MAKE_TYPE_BRANCH__(TMPI, T1, T2, T3, A1, A2) \
if (TSnd == TMPI && myOv.T1 && myOv.T2 ) \
{ \
A1 myNDA = myOv.A2; \
nitem = myNDA.nelem (); \
dv = myNDA.dims (); \
nd = myNDA.ndims (); \
OCTAVE_LOCAL_BUFFER(int, dimV, nd); \
\
for (octave_idx_type i = 0; i < nd; i++) \
dimV[i] = dv(i) ; \
\
T3 * LBNDA = myNDA.fortran_vec (); \
\
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec (); \
for (octave_idx_type i = 0; i < rankrec.nelem (); i++) \
{ \
info = MPI_Send \
(&t_id, 1, MPI_INT, rankrec_ptr[i], tanktag[0], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(&nitem, 1, MPI_INT, rankrec_ptr[i], tanktag[1], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(&nd, 1, MPI_INT, rankrec_ptr[i], tanktag[2], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(dimV, nd, MPI_INT, rankrec_ptr[i], tanktag[3], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(LBNDA, nitem, TSnd, rankrec_ptr[i], tanktag[4], comm); \
if (info != MPI_SUCCESS) return info; \
} \
}
#define __MAKE_CMPLX_TYPE_BRANCH__(TMPI,T1,T2,T3,A1,A2) \
if (TSnd == TMPI && myOv.T1 && myOv.T2) \
{ \
A1 myNDA = myOv.A2; \
nitem = myNDA.nelem (); \
OCTAVE_LOCAL_BUFFER(T3, LBNDA1, nitem); \
OCTAVE_LOCAL_BUFFER(T3, LBNDA2, nitem); \
\
dv = myNDA.dims (); \
nd = myNDA.ndims (); \
OCTAVE_LOCAL_BUFFER(int, dimV, nd); \
\
for (octave_idx_type i = 0; i < nd; ++i) \
dimV[i] = dv(i); \
\
for (octave_idx_type i = 0; i < nitem; ++i) \
{ \
LBNDA1[i] = real (myNDA(i)); \
LBNDA2[i] = imag (myNDA(i)); \
} \
\
\
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec (); \
for (octave_idx_type i = 0; i< rankrec.nelem (); i++) \
{ \
info = MPI_Send \
(&t_id, 1, MPI_INT, rankrec_ptr[i], tanktag[0], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(&nitem, 1, MPI_INT, rankrec_ptr[i], tanktag[1], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(&nd, 1, MPI_INT, rankrec_ptr[i], tanktag[2], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(dimV, nd, MPI_INT, rankrec_ptr[i], tanktag[3], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(LBNDA1, nitem, TSnd, rankrec_ptr[i], tanktag[4], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(LBNDA2, nitem, TSnd, rankrec_ptr[i], tanktag[5], comm); \
if (info != MPI_SUCCESS) return info; \
} \
}
__MAKE_CMPLX_TYPE_BRANCH__(MPI_DOUBLE, is_complex_type (), is_double_type (),
double,ComplexNDArray,complex_array_value())
else
__MAKE_CMPLX_TYPE_BRANCH__(MPI_FLOAT, is_complex_type (), is_single_type (),
double, FloatComplexNDArray,
float_complex_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_DOUBLE, is_real_type (), is_double_type (),
double, NDArray, array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_INT, is_bool_type (), is_real_type (),
bool, boolNDArray, bool_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_FLOAT, is_single_type (), is_real_type (),
float, FloatNDArray, float_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_BYTE, is_int8_type (), is_real_type (),
octave_int8, int8NDArray, int8_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_SHORT, is_int16_type (), is_real_type (),
octave_int16, int16NDArray, int16_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_INT, is_int32_type (), is_real_type (),
octave_int32, int32NDArray, int32_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_LONG_LONG, is_int64_type (), is_real_type (),
octave_int64, int64NDArray, int64_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_UNSIGNED_CHAR, is_uint8_type (), is_real_type (),
octave_uint8, uint8NDArray, uint8_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_UNSIGNED_SHORT, is_uint16_type (), is_real_type (),
octave_uint16, uint16NDArray, uint16_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_UNSIGNED, is_uint32_type (), is_real_type (),
octave_uint32, uint32NDArray, uint32_array_value ())
else
__MAKE_TYPE_BRANCH__(MPI_UNSIGNED_LONG_LONG, is_uint64_type (),
is_real_type (), octave_uint64, uint64NDArray,
uint64_array_value ())
else
error ("MPI_Send: matrix with unexpected data type");
return (info);
#undef __MAKE_TYPE_BRANCH__
#undef __MAKE_CMPLX_TYPE_BRANCH__
}
int
send_sp_mat (int t_id, MPI_Datatype TSnd, MPI_Comm comm,
const octave_value &MyOv, const Array &rankrec,
int mytag)
{
OCTAVE_LOCAL_BUFFER(int,tanktag,6);
int info;
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
tanktag[3] = mytag + 3;
tanktag[4] = mytag + 4;
tanktag[5] = mytag + 5;
#define __MAKE_TYPE_BRANCH__(TMPI,T0,T1,T2,A1) \
if (TSnd == TMPI and MyOv.T1) \
{ \
OCTAVE_LOCAL_BUFFER(int, s, 3); \
T2 m = MyOv.A1; \
OCTAVE_LOCAL_BUFFER(int, sridx, m.capacity ()); \
OCTAVE_LOCAL_BUFFER(int, scidx, m.cols () + 1); \
s[0]= m.rows (); \
s[1]= m.cols (); \
s[2]= m.capacity (); \
\
for (octave_idx_type ix = 0; ix < m.cols () + 1; ix++) \
scidx[ix]= m.cidx (ix); \
\
OCTAVE_LOCAL_BUFFER(T0, sdata, m.capacity ()); \
\
for (octave_idx_type ix = 0; ix < m.capacity (); ix++) \
{ \
sdata[ix]= m.data (ix); \
sridx[ix]= m.ridx (ix); \
} \
\
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec (); \
for (octave_idx_type i = 0; i < rankrec.nelem (); i++) \
{ \
info = MPI_Send \
(&t_id, 1, MPI_INT, rankrec_ptr[i], tanktag[0], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(s, 3, MPI_INT, rankrec_ptr[i], tanktag[1], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(sridx, m.capacity (), MPI_INT, rankrec_ptr[i], \
tanktag[2], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(scidx, m.cols () + 1, MPI_INT, rankrec_ptr[i], \
tanktag[3], comm); \
if (info != MPI_SUCCESS) return info; \
\
info = MPI_Send \
(sdata, m.capacity (), TSnd, rankrec_ptr[i], \
tanktag[4], comm); \
if (info != MPI_SUCCESS) return info; \
} \
}
__MAKE_TYPE_BRANCH__(MPI_INT, bool, is_bool_type (),
SparseBoolMatrix, sparse_bool_matrix_value ())
else
__MAKE_TYPE_BRANCH__(MPI_DOUBLE, double, is_real_type (),
SparseMatrix, sparse_matrix_value ())
else if (TSnd == MPI_DOUBLE and MyOv.is_complex_type ())
{
SparseComplexMatrix m = MyOv.sparse_complex_matrix_value ();
OCTAVE_LOCAL_BUFFER(int,s,3);
s[0]= m.rows ();
s[1]= m.cols ();
s[2]= m.capacity ();
OCTAVE_LOCAL_BUFFER(int,sridx,m.capacity());
OCTAVE_LOCAL_BUFFER(int,scidx,m.cols()+1);
for (octave_idx_type ix = 0; ix < m.cols () + 1; ix++)
scidx[ix]= m.cidx(ix);
OCTAVE_LOCAL_BUFFER(double, sdata1, m.capacity());
OCTAVE_LOCAL_BUFFER(double, sdata2, m.capacity());
// Fill them with their respective value
for (octave_idx_type ix = 0; ix < m.capacity (); ix++)
{
sdata1[ix] = real (m.data(ix));
sdata2[ix] = imag (m.data(ix));
sridx[ix] = m.ridx(ix);
}
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec ();
for (octave_idx_type i = 0; i < rankrec.nelem (); i++)
{
info = MPI_Send
(&t_id, 1, MPI_INT, rankrec_ptr[i], tanktag[0], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(s, 3, MPI_INT, rankrec_ptr[i], tanktag[1], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(sridx, m.capacity (), MPI_INT, rankrec_ptr[i], tanktag[2], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(scidx, m.cols () + 1, MPI_INT, rankrec_ptr[i], tanktag[3], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(sdata1, m.capacity (), TSnd, rankrec_ptr[i], tanktag[4], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(sdata2, m.capacity (), TSnd, rankrec_ptr[i], tanktag[5], comm);
if (info != MPI_SUCCESS) return info;
}
}
return(info);
}
int
send_string (int t_id, MPI_Comm comm, std::string oi8,
const Array &rankrec, int mytag)
{
int info;
int nitem = oi8.length ();
int tanktag[3];
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
char i8[nitem+1];
strcpy (i8, oi8.c_str ());
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec ();
for (octave_idx_type i = 0; i < rankrec.nelem (); i++)
{
info = MPI_Send
(&t_id, 1, MPI_INT, rankrec_ptr[i], mytag, comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(&nitem, 1, MPI_INT, rankrec_ptr[i], tanktag[1], comm);
if (info != MPI_SUCCESS) return info;
info = MPI_Send
(&i8, nitem + 1, MPI_CHAR, rankrec_ptr[i], tanktag[2], comm);
if (info != MPI_SUCCESS) return info;
}
return(info);
}
int
send_cell (int t_id, MPI_Comm comm, Cell cell,
const Array &rankrec, int mytag)
{
/*-------------------------------------*/
/* we first store nelems and then */
/* recursively the elements themselves */
// Lists of items to send
// type_id to identify octave_value
// n for the cell capacity
// nd for number of dimensions
// dimvec derived datatype
// item of cell
int n = cell.capacity ();
int info;
int tanktag[5];
tanktag[0] = mytag;
tanktag[1] = mytag + 1;
tanktag[2] = mytag + 2;
tanktag[3] = mytag + 3;
tanktag[4] = mytag + 4;
int newtag = tanktag[4];
dim_vector vdim = cell.dims ();
int nd = cell.ndims ();
// Declare here the octave_local_buffers
OCTAVE_LOCAL_BUFFER(int,dimV,nd);
for (octave_idx_type i = 0; i < nd; i++)
dimV[i] = vdim(i) ;
// Now start the big loop
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec ();
for (octave_idx_type i = 0; i < rankrec.nelem (); i++)
{
info = MPI_Send (&t_id, 1, MPI_INT, rankrec_ptr[i],
tanktag[0], comm);
if (info != MPI_SUCCESS)
return info;
info = MPI_Send (&n, 1, MPI_INT, rankrec_ptr[i],
tanktag[1], comm);
if (info != MPI_SUCCESS)
return info;
info = MPI_Send (&nd, 1, MPI_INT, rankrec_ptr[i],
tanktag[2], comm);
if (info != MPI_SUCCESS)
return info;
// send the dim vector
info = MPI_Send (dimV, nd, MPI_INT, rankrec_ptr[i],
tanktag[3], comm);
if (info != MPI_SUCCESS)
return info;
int cap;
// Now focus on every single octave_value
for (octave_idx_type j = 0; j < n; j++)
{
octave_value ov = cell.data ()[j];
cap = ov.capacity ();
info = MPI_Send (&cap, 1, MPI_INT, rankrec_ptr[i],
newtag, comm);
if (info != MPI_SUCCESS)
return info;
newtag = newtag + ov.capacity ();
info = send_class (comm, ov, rankrec, newtag);
if (info != MPI_SUCCESS)
return info;
}
}
return (info);
}
int
send_struct (int t_id, MPI_Comm comm, octave_map map,
const Array &rankrec, int mytag)
{ /* we store nkeys, */
int n = map.nfields ();
int info;
OCTAVE_LOCAL_BUFFER(int,tanktag,2);
tanktag[0] = mytag; //t-id
tanktag[1] = mytag + 1; // n
int tagcap = mytag + 2;
int ntagkey = mytag + 3; // string
// struct array dimensions (ND)
// each key stores ND field-values
dim_vector struc_dims = map.dims ();
dim_vector conts_dims;
// Now we start the big loop
const octave_idx_type *rankrec_ptr = rankrec.fortran_vec ();
for (octave_idx_type i = 0; i < rankrec.nelem (); i++)
{
info = MPI_Send (&t_id, 1, MPI_INT, rankrec_ptr[i],
tanktag[0], comm);
if (info != MPI_SUCCESS)
return info;
info = MPI_Send (&n, 1, MPI_INT, rankrec_ptr[i],
tanktag[1], comm);
if (info != MPI_SUCCESS)
return info;
// This is to avoid confusion between tags of strings and tags of Cells
int ntagCell = ntagkey + 1;
// iterate through keys(fnames)
int scap;
for (octave_map::const_iterator p = map.begin (); p != map.end (); p++)
{
// field name
std::string key = map.key (p);
// Cell w/ND contents
Cell conts = map.contents (p);
// each elemt should have same ND
conts_dims = conts.dims ();
if (struc_dims != conts_dims)
{
error ("MPI_Send: inconsistent map dims\n");
return (MPI_ERR_UNKNOWN);
}
// Sending capacity of octave_cell
scap = conts.capacity ();
info = MPI_Send
(&scap, 1, MPI_INT, rankrec_ptr[i], tagcap, comm);
if (info != MPI_SUCCESS) return info;
tagcap = tagcap + 1;
ntagkey = ntagkey + 3;
info = send_class (comm, key, rankrec, ntagkey);
if (info != MPI_SUCCESS) return info;
// Sending Cell
ntagCell = ntagCell + conts.capacity();
info = send_class (comm, conts, rankrec, ntagCell);
if (info != MPI_SUCCESS) return info;
}
if (n != map.nfields ())
{
error ("MPI_Send: inconsistent map length\n");
return (MPI_ERR_UNKNOWN);
}
}
return (info);
}
int
send_class (MPI_Comm comm, const octave_value &ov,
const Array &rankrec,
int mytag)
{
/*---------------------------------- */
/* varname-strlength 1st, dims[ndim] */
/* and then appropriate specific info */
int t_id = ov.type_id ();
const std::string mystring = ov.type_name ();
MPI_Datatype TSnd;
// range
if (mystring == "range")
return (send_range (t_id, comm, ov.range_value (), rankrec, mytag));
// scalar
else if (mystring == "scalar")
return (send_scalar (t_id, MPI_DOUBLE, comm, ov.scalar_value (),
rankrec, mytag));
else if (mystring == "int8 scalar")
return (send_scalar (t_id, MPI_BYTE, comm, ov.int8_scalar_value (),
rankrec, mytag));
else if (mystring == "int16 scalar")
return (send_scalar (t_id, MPI_SHORT, comm, ov.int16_scalar_value (),
rankrec, mytag));
else if (mystring == "int32 scalar")
return (send_scalar (t_id, MPI_INT, comm, ov.int32_scalar_value (),
rankrec, mytag));
else if (mystring == "int64 scalar")
return (send_scalar (t_id, MPI_LONG_LONG, comm, ov.int64_scalar_value (),
rankrec, mytag));
else if (mystring == "uint8 scalar")
return (send_scalar (t_id, MPI_UNSIGNED_CHAR, comm, ov.uint8_scalar_value (),
rankrec, mytag));
else if (mystring == "uint16 scalar")
return (send_scalar (t_id, MPI_UNSIGNED_SHORT, comm,
ov.uint16_scalar_value (), rankrec, mytag));
else if (mystring == "uint32 scalar")
return (send_scalar (t_id, MPI_UNSIGNED, comm, ov.uint32_scalar_value (),
rankrec, mytag));
else if (mystring == "uint64 scalar")
return (send_scalar (t_id, MPI_UNSIGNED_LONG_LONG, comm,
ov.uint64_scalar_value (), rankrec, mytag));
else if (mystring == "bool")
return (send_scalar (t_id, MPI_INT, comm, ov.int_value (), rankrec, mytag));
else if (mystring == "float scalar")
return (send_scalar (t_id, MPI_FLOAT, comm, ov.float_value (),
rankrec, mytag));
else if (mystring == "complex scalar")
return (send_scalar (t_id, MPI_DOUBLE, comm, ov.complex_value (), rankrec,
mytag));
else if (mystring == "float complex scalar")
return (send_scalar (t_id, MPI_FLOAT, comm, ov.float_complex_value (),
rankrec, mytag));
// matrix
else if (mystring == "matrix")
return (send_matrix (t_id, MPI_DOUBLE, comm, ov, rankrec, mytag));
else if (mystring == "bool matrix")
return (send_matrix (t_id, MPI_INT, comm, ov, rankrec, mytag));
else if (mystring == "int8 matrix")
return (send_matrix (t_id, MPI_BYTE, comm, ov, rankrec, mytag));
else if (mystring == "int16 matrix")
return (send_matrix (t_id, MPI_SHORT, comm, ov, rankrec, mytag));
else if (mystring == "int32 matrix")
return (send_matrix (t_id, MPI_INT, comm, ov, rankrec, mytag));
else if (mystring == "int64 matrix")
return (send_matrix (t_id, MPI_LONG_LONG, comm, ov, rankrec, mytag));
else if (mystring == "uint8 matrix")
return (send_matrix (t_id, MPI_UNSIGNED_CHAR, comm, ov, rankrec, mytag));
else if (mystring == "uint16 matrix")
return (send_matrix (t_id, MPI_UNSIGNED_SHORT, comm, ov, rankrec, mytag));
else if (mystring == "uint32 matrix")
return (send_matrix (t_id, MPI_UNSIGNED, comm, ov, rankrec, mytag));
else if (mystring == "uint64 matrix")
return (send_matrix (t_id, MPI_UNSIGNED_LONG_LONG, comm, ov, rankrec,
mytag));
// complex matrix
else if (mystring == "complex matrix")
return (send_matrix (t_id, MPI_DOUBLE, comm, ov, rankrec, mytag));
else if (mystring == "float complex matrix")
return (send_matrix (t_id, MPI_FLOAT, comm, ov, rankrec, mytag));
// sparse matrix
else if (mystring == "sparse bool matrix")
return (send_sp_mat (t_id, MPI_INT, comm, ov, rankrec, mytag));
else if (mystring == "sparse matrix")
return (send_sp_mat (t_id, MPI_DOUBLE, comm, ov, rankrec, mytag));
else if (mystring == "sparse complex matrix")
return (send_sp_mat (t_id, MPI_DOUBLE, comm, ov, rankrec, mytag));
else if (mystring == "string")
return (send_string (t_id, comm, ov.string_value (), rankrec, mytag));
else if (mystring == "sq_string")
return (send_string (t_id, comm, ov.string_value (), rankrec, mytag));
else if (mystring == "struct")
return (send_struct (t_id, comm, ov.map_value (), rankrec, mytag));
else if (mystring == "cell")
return (send_cell (t_id, comm, ov.cell_value (), rankrec, mytag));
else if (mystring == "")
{
error ("MPI_Send: unknown class\n");
return (MPI_ERR_UNKNOWN);
}
else
{
error ("MPI_Send: unsupported class %s\n", ov.type_name ().c_str ());
return (MPI_ERR_UNKNOWN);
}
}
DEFUN_DLD(MPI_Send, args, nargout,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {@var{INFO} =} MPI_Send(@var{VALUE},@var{RANKS},@var{TAG},@var{COMM})\n\
Transmit an Octave variable as a set of MPI message.\n\
Return an integer @var{INFO} to indicate success or failure.\n\
@example\n\
@group\n\
@var{VALUE} must be an octave variable \n\
@var{RANKS} must be a vector containing the list of rank destination processes \n\
@var{TAG} must be an integer to identify the message by openmpi \n\
@var{COMM} must be an octave communicator object created by MPI_Comm_Load function \n\
@end group\n\
@end example\n\
\n\
@seealso{MPI_Comm_Load,MPI_Init,MPI_Finalize,MPI_Recv}\n\
@end deftypefn")
{
octave_value retval;
int nargin = args.length ();
if (nargin != 4 )
print_usage ();
else
{
Array tankrank =
args(1).octave_idx_type_vector_value ();
int mytag = args(2).int_value ();
if (! error_state)
{
if (! simple_type_loaded)
{
simple::register_type ();
simple_type_loaded = true;
mlock ();
}
if (args(3).type_id () == simple::static_type_id ())
{
const octave_base_value& rep = args(3).get_rep ();
const simple& B = ((const simple &)rep);
MPI_Comm comm = ((const simple&) B).comunicator_value ();
int info = send_class (comm, args(0), tankrank, mytag);
comm = NULL;
retval = info;
}
else
error ("MPI_Send: Please enter octave comunicator object!");
}
}
return retval;
}
mpi/src/Makefile 0000644 0000000 0000000 00000001226 12262642123 012221 0 ustar 0000000 0000000 MPICC ?= mpic++
OFMPIINC ?= $(shell $(MPICC) -showme:compile | sed -e "s/-pthread/-lpthread/g")
MPIINC := $(OFMPIINC)
OFMPILIBS ?= $(shell $(MPICC) -showme:link | sed -e "s/-pthread/ /g")
MPILIBS := $(OFMPILIBS)
MKOCTFILE ?= mkoctfile
all: MPI_Init.oct \
MPI_Initialized.oct \
MPI_Comm_rank.oct \
MPI_Comm_size.oct \
MPI_Finalize.oct \
MPI_Finalized.oct \
MPI_Send.oct \
MPI_Recv.oct \
MPI_Barrier.oct \
MPI_Iprobe.oct \
MPI_Probe.oct \
MPI_Comm_Load.oct \
MPI_Comm_Test.oct \
MPI_Get_processor_name.oct \
%.oct: %.cc
$(MKOCTFILE) $(MPIINC) $(MPILIBS) $<
clean:
$(RM) *.o *.oct *~
mpi/src/simple.h 0000644 0000000 0000000 00000003075 12262642123 012227 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#include "mpi.h"
#include
class simple : public octave_base_value
{
public:
// Constructor
simple (const std::string _name = "", MPI_Comm _Comm_Value = MPI_COMM_WORLD)
: octave_base_value (), name (_name), Comm_Value(_Comm_Value) { }
void print (std::ostream& os, bool pr_as_read_syntax = false) const
{ os << name << std::endl; }
~simple(void) { Comm_Value = NULL; }
bool is_defined (void) const { return true; }
MPI_Comm comunicator_value (bool = false) const { return Comm_Value; }
const std::string name_value (bool = false) const { return name; }
private:
const std::string name;
MPI_Comm Comm_Value;
DECLARE_OCTAVE_ALLOCATOR;
DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
};
DEFINE_OCTAVE_ALLOCATOR (simple);
DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (simple, "simple", "simple");
static bool simple_type_loaded = false;
mpi/src/simpleop.h 0000644 0000000 0000000 00000004501 12262642123 012561 0 ustar 0000000 0000000 // Copyright (C) 2009 Riccardo Corradini
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see .
#include "mpi.h"
#include
class simpleop : public octave_base_value
{
public:
// Constructor
simpleop (const std::string _name = "", MPI_Op _Op_Value = MPI_OP_NULL )
: octave_base_value (), name (_name), Op_Value(_Op_Value)
{
}
void set ( MPI_Op _Op_Value)
{
if(_Op_Value == MPI_BAND) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_BOR) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_BXOR) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_LAND) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_LOR) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_LXOR) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_MAX) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_MIN) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_OP_NULL) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_PROD) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_REPLACE) {Op_Value=_Op_Value;};
if(_Op_Value == MPI_SUM) {Op_Value=_Op_Value;}
else {printf("This is not an MPI Operator!\n");Op_Value=MPI_OP_NULL;};
}
void print (std::ostream& os, bool pr_as_read_syntax = false) const
{
os << name << std::endl;
}
~simpleop(void)
{
Op_Value = MPI_OP_NULL;
}
bool is_defined (void) const { return true; }
MPI_Op operator_value (bool = false) const { return Op_Value; }
const std::string name_value (bool = false) const { return name; }
private:
const std::string name;
MPI_Op Op_Value;
DECLARE_OCTAVE_ALLOCATOR
DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
};
DEFINE_OCTAVE_ALLOCATOR (simpleop);
DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (simpleop, "simpleop", "simpleop");
static bool simpleop_type_loaded = false;