Skip to content
Snippets Groups Projects
Commit b8a2160f authored by Youhei SASAKI's avatar Youhei SASAKI :beer:
Browse files

Imported Upstream version 0.2.0

parents
No related branches found
No related tags found
No related merge requests found
lib/**/*.rb
bin/*
-
features/**/*.feature
LICENSE.txt
.rspec 0 → 100644
--color
Gemfile 0 → 100644
source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "rspec", "~> 2.3.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
gem "rcov", ">= 0"
gem "narray", ">= 0"
end
GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.2)
git (1.2.5)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
narray (0.5.9.9)
rake (0.8.7)
rcov (0.9.9)
rspec (2.3.0)
rspec-core (~> 2.3.0)
rspec-expectations (~> 2.3.0)
rspec-mocks (~> 2.3.0)
rspec-core (2.3.1)
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
narray
rcov
rspec (~> 2.3.0)
Copyright (c) 2011 Seiya Nishizawa
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
= Ruby-MPI
Ruby-MPI is a ruby binding of Message Passing Interface (MPI), which is an API specification that allows processes to communicate with one another by sending and receiving messages.
== Install
# gem install ruby-mpi
== Contributing to Ruby-MPI
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
== Copyright
Copyright (c) 2011 Seiya Nishizawa. See LICENSE.txt for
further details.
Rakefile 0 → 100644
require 'rubygems'
require 'bundler'
require "rake/clean"
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "ruby-mpi"
gem.homepage = "http://github.com/seiya/ruby-mpi"
gem.license = "MIT"
gem.summary = "A ruby binding of MPI"
gem.description = "A ruby binding of Message Passing Interface (MPI), which is an API specification that allows processes to communicate with one another by sending and receiving messages."
gem.email = "seiya@gfd-dennou.org"
gem.authors = ["Seiya Nishizawa"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
# gem.add_development_dependency 'rspec', '> 1.2.3'
end
Jeweler::RubygemsDotOrgTasks.new
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end
task :default => :spec
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "ruby-mpi #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
CLEAN.include("ext/mpi/*.o")
CLEAN.include("ext/mpi/mkmf.log")
CLOBBER.include("ext/mpi/mpi.so")
CLOBBER.include("ext/mpi/Makefile")
0.2.0
\ No newline at end of file
require "mkmf"
CONFIG['CC'] = "mpicc"
gem_path = nil
begin
require "rubygems"
if (spec = Gem.source_index.find_name("narray")).any?
gem_path = spec.last.full_gem_path
end
rescue LoadError
dir_config("narray", Config::CONFIG["sitearchdir"])
end
find_header("narray.h", gem_path)
create_makefile("mpi")
This diff is collapsed.
begin
require "rubygems"
rescue LoadError
end
require "narray"
require "mpi.so"
--- !ruby/object:Gem::Specification
name: ruby-mpi
version: !ruby/object:Gem::Version
prerelease:
version: 0.2.0
platform: ruby
authors:
- Seiya Nishizawa
autorequire:
bindir: bin
cert_chain: []
date: 2011-04-22 00:00:00 Z
dependencies:
- !ruby/object:Gem::Dependency
name: rspec
requirement: &id001 !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: 2.3.0
type: :development
prerelease: false
version_requirements: *id001
- !ruby/object:Gem::Dependency
name: bundler
requirement: &id002 !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: 1.0.0
type: :development
prerelease: false
version_requirements: *id002
- !ruby/object:Gem::Dependency
name: jeweler
requirement: &id003 !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: 1.5.2
type: :development
prerelease: false
version_requirements: *id003
- !ruby/object:Gem::Dependency
name: rcov
requirement: &id004 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
type: :development
prerelease: false
version_requirements: *id004
- !ruby/object:Gem::Dependency
name: narray
requirement: &id005 !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
type: :development
prerelease: false
version_requirements: *id005
description: A ruby binding of Message Passing Interface (MPI), which is an API specification that allows processes to communicate with one another by sending and receiving messages.
email: seiya@gfd-dennou.org
executables: []
extensions:
- ext/mpi/extconf.rb
extra_rdoc_files:
- LICENSE.txt
- README.rdoc
files:
- .document
- .rspec
- Gemfile
- Gemfile.lock
- LICENSE.txt
- README.rdoc
- Rakefile
- VERSION
- ext/mpi/extconf.rb
- ext/mpi/mpi.c
- lib/mpi.rb
- ruby-mpi.gemspec
- samples/hello.rb
- samples/narray.rb
- spec/ruby-mpi_spec.rb
- spec/spec_helper.rb
homepage: http://github.com/seiya/ruby-mpi
licenses:
- MIT
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
hash: -3549605766415082841
segments:
- 0
version: "0"
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
requirements: []
rubyforge_project:
rubygems_version: 1.7.2
signing_key:
specification_version: 3
summary: A ruby binding of MPI
test_files:
- spec/ruby-mpi_spec.rb
- spec/spec_helper.rb
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{ruby-mpi}
s.version = "0.2.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Seiya Nishizawa"]
s.date = %q{2011-04-22}
s.description = %q{A ruby binding of Message Passing Interface (MPI), which is an API specification that allows processes to communicate with one another by sending and receiving messages.}
s.email = %q{seiya@gfd-dennou.org}
s.extensions = ["ext/mpi/extconf.rb"]
s.extra_rdoc_files = [
"LICENSE.txt",
"README.rdoc"
]
s.files = [
".document",
".rspec",
"Gemfile",
"Gemfile.lock",
"LICENSE.txt",
"README.rdoc",
"Rakefile",
"VERSION",
"ext/mpi/extconf.rb",
"ext/mpi/mpi.c",
"lib/mpi.rb",
"ruby-mpi.gemspec",
"samples/hello.rb",
"samples/narray.rb",
"spec/ruby-mpi_spec.rb",
"spec/spec_helper.rb"
]
s.homepage = %q{http://github.com/seiya/ruby-mpi}
s.licenses = ["MIT"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.7.2}
s.summary = %q{A ruby binding of MPI}
s.test_files = [
"spec/ruby-mpi_spec.rb",
"spec/spec_helper.rb"
]
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_development_dependency(%q<rcov>, [">= 0"])
s.add_development_dependency(%q<narray>, [">= 0"])
else
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_dependency(%q<rcov>, [">= 0"])
s.add_dependency(%q<narray>, [">= 0"])
end
else
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_dependency(%q<rcov>, [">= 0"])
s.add_dependency(%q<narray>, [">= 0"])
end
end
require "mpi"
MPI.Init
world = MPI::Comm::WORLD
rank = world.rank
if rank == 0
(world.size-1).times do |i|
str ="\x00"*100
world.Recv(str, i+1, 0)
p str
end
else
message = "Hello from #{rank}"
world.Send(message, 0, 0)
end
MPI.Finalize
require "mpi"
MPI.Init
world = MPI::Comm::WORLD
rank = world.rank
if rank == 0
(world.size-1).times do |i|
a = NArray.float(2)
world.Recv(a, i+1, 1)
p a
end
else
world.Send(NArray[1.0,2], 0, 1)
end
MPI.Finalize
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "MPI" do
before(:all) do
MPI.Init()
end
after(:all) do
MPI.Finalize()
end
before do
@world = MPI::Comm::WORLD
end
it "should give version" do
MPI::VERSION.class.should eql(Fixnum)
MPI::SUBVERSION.class.should eql(Fixnum)
end
it "should give rank and size" do
@world.rank.class.should eql(Fixnum)
@world.size.class.should eql(Fixnum)
@world.size.should > 0
end
it "should send and receive String" do
rank = @world.rank
message = "Hello from #{rank}"
tag = 0
@world.Send(message, 0, tag) if rank != 0
if rank == 0
(@world.size-1).times do |i|
str = " "*"Hello from #{i+1}".length
status = @world.Recv(str, i+1, tag)
status.source.should eql(i+1)
status.tag.should eql(tag)
status.error.should eq(MPI::SUCCESS)
str.should match(/\AHello from #{i+1}/)
end
end
end
it "should send and receive NArray" do
tag = 0
rank = @world.rank
[NArray[1,2,3], NArray[3.0,2.0,1.0]].each do |ary0|
ary0 = NArray[1,2,3]
@world.Send(ary0, 0, tag) if rank != 0
if rank == 0
(@world.size-1).times do |i|
ary1 = NArray.new(ary0.typecode, ary0.total)
status = @world.Recv(ary1, i+1, tag)
status.source.should eql(i+1)
status.tag.should eql(tag)
status.error.should eq(MPI::SUCCESS)
ary1.should == ary0
end
end
end
end
it "should send and receive without blocking" do
tag = 0
rank = @world.rank
message = "Hello from #{rank}"
if rank != 0
request = @world.Isend(message, 0, tag)
status = request.Wait
# status.source.should eql(rank)
status.tag.should eql(tag)
end
if rank == 0
(@world.size-1).times do |i|
str = " "*"Hello from #{i+1}".length
request_recv = @world.Irecv(str, i+1, tag)
status = request_recv.Wait
status.source.should eql(i+1)
status.tag.should eql(tag)
str.should match(/\AHello from #{i+1}/)
end
end
end
it "should gather data" do
rank = @world.rank
size = @world.size
root = 0
bufsize = 2
sendbuf = rank.to_s*bufsize
recvbuf = rank == root ? "?"*bufsize*size : nil
@world.Gather(sendbuf, recvbuf, root)
if rank == root
str = ""
size.times{|i| str << i.to_s*bufsize}
recvbuf.should eql(str)
end
end
it "should gather data to all processes (allgather)" do
rank = @world.rank
size = @world.size
bufsize = 2
sendbuf = rank.to_s*bufsize
recvbuf = "?"*bufsize*size
@world.Allgather(sendbuf, recvbuf)
str = ""
size.times{|i| str << i.to_s*bufsize}
recvbuf.should eql(str)
end
it "should broad cast data (bcast)" do
rank = @world.rank
root = 0
bufsize = 2
if rank == root
buffer = rank.to_s*bufsize
else
buffer = " "*bufsize
end
@world.Bcast(buffer, root)
buffer.should eql(root.to_s*bufsize)
end
it "should scatter data" do
rank = @world.rank
size = @world.size
root = 0
bufsize = 2
if rank == root
sendbuf = ""
size.times{|i| sendbuf << i.to_s*bufsize}
else
sendbuf = nil
end
recvbuf = " "*bufsize
@world.Scatter(sendbuf, recvbuf, root)
recvbuf.should eql(rank.to_s*bufsize)
end
it "should send and recv data (sendrecv)" do
rank = @world.rank
size = @world.size
dest = rank-1
dest = size-1 if dest < 0
#dest = MPI::PROC_NULL if dest < 0
source = rank+1
source = 0 if source > size-1
#source = MPI::PROC_NULL if source > size-1
sendtag = rank
recvtag = source
bufsize = 2
sendbuf = rank.to_s*bufsize
recvbuf = " "*bufsize
@world.Sendrecv(sendbuf, dest, sendtag, recvbuf, source, recvtag);
if source != MPI::PROC_NULL
recvbuf.should eql(source.to_s*bufsize)
end
end
it "should change data between each others (alltoall)" do
rank = @world.rank
size = @world.size
bufsize = 2
sendbuf = rank.to_s*bufsize*size
recvbuf = "?"*bufsize*size
@world.Alltoall(sendbuf, recvbuf)
str = ""
size.times{|i| str << i.to_s*bufsize}
recvbuf.should eql(str)
end
it "should reduce data" do
rank = @world.rank
size = @world.size
root = 0
bufsize = 2
sendbuf = NArray.to_na([rank]*bufsize)
recvbuf = rank == root ? NArray.new(sendbuf.typecode,bufsize) : nil
@world.Reduce(sendbuf, recvbuf, MPI::Op::SUM, root)
if rank == root
ary = NArray.new(sendbuf.typecode,bufsize).fill(size*(size-1)/2.0)
recvbuf.should == ary
end
end
it "should reduce data and send to all processes (allreduce)" do
rank = @world.rank
size = @world.size
bufsize = 2
sendbuf = NArray.to_na([rank]*bufsize)
recvbuf = NArray.new(sendbuf.typecode,bufsize)
@world.Allreduce(sendbuf, recvbuf, MPI::Op::SUM)
ary = NArray.new(sendbuf.typecode,bufsize).fill(size*(size-1)/2.0)
recvbuf.should == ary
end
it "should not raise exception in calling barrier" do
@world.Barrier
end
it "shoud raise exeption" do
lambda{ @world.Send("", @world.size+1, 0) }.should raise_error(MPI::ERR::RANK)
@world.Errhandler.should eql(MPI::Errhandler::ERRORS_RETURN)
end
end
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'ext', 'mpi'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'mpi'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment