ruby-mpi 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,13 +17,13 @@ describe "MPI" do
17
17
  end
18
18
 
19
19
  it "should give version" do
20
- expect(MPI::VERSION.class).to eq(Fixnum)
21
- expect(MPI::SUBVERSION.class).to eq(Fixnum)
20
+ expect(MPI::VERSION.class).to eq(Integer)
21
+ expect(MPI::SUBVERSION.class).to eq(Integer)
22
22
  end
23
23
 
24
24
  it "should give rank and size" do
25
- expect(@world.rank.class).to eql(Fixnum)
26
- expect(@world.size.class).to eql(Fixnum)
25
+ expect(@world.rank.class).to eql(Integer)
26
+ expect(@world.size.class).to eql(Integer)
27
27
  expect(@world.size).to be > 0
28
28
  end
29
29
 
@@ -69,13 +69,17 @@ describe "MPI" do
69
69
  status = request.Wait
70
70
  end
71
71
  if rank == 0
72
+ request_recv = []
73
+ str = []
72
74
  (@world.size-1).times do |i|
73
- str = " "*"Hello from #{i+1}".length
74
- request_recv = @world.Irecv(str, i+1, tag)
75
- status = request_recv.Wait
76
- expect(status.source).to eql(i+1)
77
- expect(status.tag).to eql(tag)
78
- expect(str).to match(/\AHello from #{i+1}/)
75
+ str.push " "*"Hello from #{i+1}".length
76
+ request_recv.push @world.Irecv(str[-1], i+1, tag)
77
+ end
78
+ status = MPI.Waitall(request_recv)
79
+ (@world.size-1).times do |i|
80
+ expect(status[i].source).to eql(i+1)
81
+ expect(status[i].tag).to eql(tag)
82
+ expect(str[i]).to match(/\AHello from #{i+1}/)
79
83
  end
80
84
  end
81
85
  end
@@ -85,12 +89,71 @@ describe "MPI" do
85
89
  size = @world.size
86
90
  root = 0
87
91
  bufsize = 2
88
- sendbuf = rank.to_s*bufsize
92
+ sendbuf = rank.to_s[0,1]*bufsize
89
93
  recvbuf = rank == root ? "?"*bufsize*size : nil
90
94
  @world.Gather(sendbuf, recvbuf, root)
91
95
  if rank == root
92
96
  str = ""
93
- size.times{|i| str << i.to_s*bufsize}
97
+ size.times{|i| str << i.to_s[0,1]*bufsize}
98
+ expect(recvbuf).to eql(str)
99
+ end
100
+ end
101
+
102
+ it "should gather data without blocking" do
103
+ rank = @world.rank
104
+ size = @world.size
105
+ root = 0
106
+ bufsize = 2
107
+ sendbuf = rank.to_s[0,1]*bufsize
108
+ recvbuf = rank == root ? "?"*bufsize*size : nil
109
+ request = @world.Igather(sendbuf, recvbuf, root)
110
+ if rank == root
111
+ str = ""
112
+ size.times{|i| str << i.to_s[0,1]*bufsize}
113
+ request.Wait
114
+ expect(recvbuf).to eql(str)
115
+ end
116
+ end
117
+
118
+ it "should gather data of various sizes (gatherv)" do
119
+ rank = @world.rank
120
+ size = @world.size
121
+ root = 0
122
+ sendbuf = rank.to_s*(rank+1)
123
+ recvcounts = []
124
+ displs = [0]
125
+ size.times do |i|
126
+ recvcounts.push i.to_s.length * (i+1)
127
+ displs[i+1] = displs[i] + recvcounts[-1] if i<size-1
128
+ end
129
+ bufsize = displs[-1] + recvcounts[-1]
130
+ recvbuf = rank == root ? "?"*bufsize : nil
131
+ @world.Gatherv(sendbuf, recvbuf, recvcounts, displs, root)
132
+ if rank == root
133
+ str = ""
134
+ size.times{|i| str << i.to_s*(i+1)}
135
+ expect(recvbuf).to eql(str)
136
+ end
137
+ end
138
+
139
+ it "should gather data of various sizes without blocking (igatherv)" do
140
+ rank = @world.rank
141
+ size = @world.size
142
+ root = 0
143
+ sendbuf = rank.to_s*(rank+1)
144
+ recvcounts = []
145
+ displs = [0]
146
+ size.times do |i|
147
+ recvcounts.push i.to_s.length * (i+1)
148
+ displs[i+1] = displs[i] + recvcounts[-1] if i<size-1
149
+ end
150
+ bufsize = displs[-1] + recvcounts[-1]
151
+ recvbuf = rank == root ? "?"*bufsize : nil
152
+ request = @world.Igatherv(sendbuf, recvbuf, recvcounts, displs, root)
153
+ if rank == root
154
+ str = ""
155
+ size.times{|i| str << i.to_s*(i+1)}
156
+ request.Wait
94
157
  expect(recvbuf).to eql(str)
95
158
  end
96
159
  end
@@ -99,11 +162,61 @@ describe "MPI" do
99
162
  rank = @world.rank
100
163
  size = @world.size
101
164
  bufsize = 2
102
- sendbuf = rank.to_s*bufsize
165
+ sendbuf = rank.to_s[0,1]*bufsize
103
166
  recvbuf = "?"*bufsize*size
104
167
  @world.Allgather(sendbuf, recvbuf)
105
168
  str = ""
106
- size.times{|i| str << i.to_s*bufsize}
169
+ size.times{|i| str << i.to_s[0,1]*bufsize}
170
+ expect(recvbuf).to eql(str)
171
+ end
172
+
173
+ it "should gather data to all processes without blocking (iallgather)" do
174
+ rank = @world.rank
175
+ size = @world.size
176
+ bufsize = 2
177
+ sendbuf = rank.to_s[0,1]*bufsize
178
+ recvbuf = "?"*bufsize*size
179
+ request = @world.Iallgather(sendbuf, recvbuf)
180
+ str = ""
181
+ size.times{|i| str << i.to_s[0,1]*bufsize}
182
+ request.Wait
183
+ expect(recvbuf).to eql(str)
184
+ end
185
+
186
+ it "should gather data of various sizes to all processes (allgatherv)" do
187
+ rank = @world.rank
188
+ size = @world.size
189
+ sendbuf = rank.to_s*(rank+1)
190
+ str = ""
191
+ recvcounts = []
192
+ displs = [0]
193
+ size.times do |i|
194
+ tmp = i.to_s*(i+1)
195
+ str << tmp
196
+ recvcounts.push tmp.length
197
+ displs[i+1] = displs[i] + recvcounts[-1] if i<size-1
198
+ end
199
+ recvbuf = "?"*str.length
200
+ @world.Allgatherv(sendbuf, recvbuf, recvcounts, displs)
201
+ expect(recvbuf).to eql(str)
202
+ end
203
+
204
+ it "should gather data of various sizes to all processes without blocking (iallgatherv)" do
205
+ rank = @world.rank
206
+ size = @world.size
207
+ sendbuf = rank.to_s*(rank+1)
208
+ str = ""
209
+ recvcounts = []
210
+ displs = [0]
211
+ size.times do |i|
212
+ tmp = i.to_s*(i+1)
213
+ str << tmp
214
+ recvcounts.push tmp.length
215
+ displs[i+1] = displs[i] + recvcounts[-1] if i<size-1
216
+ end
217
+ recvbuf = "?"*str.length
218
+ request = @world.Iallgatherv(sendbuf, recvbuf, recvcounts, displs)
219
+ request.Wait
107
220
  expect(recvbuf).to eql(str)
108
221
  end
109
222
 
@@ -120,6 +233,20 @@ describe "MPI" do
120
233
  expect(buffer).to eql(root.to_s*bufsize)
121
234
  end
122
235
 
236
+ it "should broad cast data without blocking (ibcast)" do
237
+ rank = @world.rank
238
+ root = 0
239
+ bufsize = 2
240
+ if rank == root
241
+ buffer = rank.to_s*bufsize
242
+ else
243
+ buffer = " "*bufsize
244
+ end
245
+ request = @world.Ibcast(buffer, root)
246
+ request.Wait
247
+ expect(buffer).to eql(root.to_s*bufsize)
248
+ end
249
+
123
250
  it "should scatter data" do
124
251
  rank = @world.rank
125
252
  size = @world.size
@@ -136,6 +263,72 @@ describe "MPI" do
136
263
  expect(recvbuf).to eql(rank.to_s*bufsize)
137
264
  end
138
265
 
266
+ it "should scatter data without blocking" do
267
+ rank = @world.rank
268
+ size = @world.size
269
+ root = 0
270
+ bufsize = 2
271
+ if rank == root
272
+ sendbuf = ""
273
+ size.times{|i| sendbuf << i.to_s*bufsize}
274
+ else
275
+ sendbuf = nil
276
+ end
277
+ recvbuf = " "*bufsize
278
+ request = @world.Iscatter(sendbuf, recvbuf, root)
279
+ request.Wait
280
+ expect(recvbuf).to eql(rank.to_s*bufsize)
281
+ end
282
+
283
+ it "should scatter data of various sizes (scatterv)" do
284
+ rank = @world.rank
285
+ size = @world.size
286
+ root = 0
287
+ if rank == root
288
+ sendbuf = ""
289
+ sendcounts = []
290
+ displs = [0]
291
+ size.times do |i|
292
+ tmp = i.to_s*(i+1)
293
+ sendbuf << tmp
294
+ sendcounts.push tmp.length
295
+ displs[i+1] = displs[i] + sendcounts[-1] if i<size-1
296
+ end
297
+ else
298
+ sendbuf = nil
299
+ sendcounts = nil
300
+ displs = nil
301
+ end
302
+ recvbuf = "?"*rank.to_s.length*(rank+1)
303
+ @world.Scatterv(sendbuf, sendcounts, displs, recvbuf, root)
304
+ expect(recvbuf).to eql(rank.to_s*(rank+1))
305
+ end
306
+
307
+ it "should scatter data of various sizes without blocking (iscatterv)" do
308
+ rank = @world.rank
309
+ size = @world.size
310
+ root = 0
311
+ if rank == root
312
+ sendbuf = ""
313
+ sendcounts = []
314
+ displs = [0]
315
+ size.times do |i|
316
+ tmp = i.to_s*(i+1)
317
+ sendbuf << tmp
318
+ sendcounts.push tmp.length
319
+ displs[i+1] = displs[i] + sendcounts[-1] if i<size-1
320
+ end
321
+ else
322
+ sendbuf = nil
323
+ sendcounts = nil
324
+ displs = nil
325
+ end
326
+ recvbuf = "?"*rank.to_s.length*(rank+1)
327
+ request = @world.Iscatterv(sendbuf, sendcounts, displs, recvbuf, root)
328
+ request.Wait
329
+ expect(recvbuf).to eql(rank.to_s*(rank+1))
330
+ end
331
+
139
332
  it "should send and recv data (sendrecv)" do
140
333
  rank = @world.rank
141
334
  size = @world.size
@@ -168,6 +361,70 @@ describe "MPI" do
168
361
  expect(recvbuf).to eql(str)
169
362
  end
170
363
 
364
+ it "should change data between each others without blocking (ialltoall)" do
365
+ rank = @world.rank
366
+ size = @world.size
367
+ bufsize = 2
368
+ sendbuf = rank.to_s*bufsize*size
369
+ recvbuf = "?"*bufsize*size
370
+ request = @world.Ialltoall(sendbuf, recvbuf)
371
+ str = ""
372
+ size.times{|i| str << i.to_s*bufsize}
373
+ request.Wait
374
+ expect(recvbuf).to eql(str)
375
+ end
376
+
377
+ it "should change data of various sizes between each others (alltoallv)" do
378
+ rank = @world.rank
379
+ size = @world.size
380
+ sendbuf = rank.to_s * (rank+1) * size
381
+ sendcounts = Array.new(size)
382
+ sdispls = Array.new(size)
383
+ len = rank.to_s.length * (rank+1)
384
+ size.times do |i|
385
+ sendcounts[i] = len
386
+ sdispls[i] = len * i
387
+ end
388
+ recvcounts = Array.new(size)
389
+ rdispls = [0]
390
+ str = ""
391
+ size.times do |i|
392
+ tmp = i.to_s * (i+1)
393
+ str << tmp
394
+ recvcounts[i] = tmp.length
395
+ rdispls[i+1] = rdispls[i] + recvcounts[i] if i<size-1
396
+ end
397
+ recvbuf = "?" * str.length
398
+ @world.Alltoallv(sendbuf, sendcounts, sdispls, recvbuf, recvcounts, rdispls)
399
+ expect(recvbuf).to eql(str)
400
+ end
401
+
402
+ it "should change data of various sizes between each others without blocking (ialltoallv)" do
403
+ rank = @world.rank
404
+ size = @world.size
405
+ sendbuf = rank.to_s * (rank+1) * size
406
+ sendcounts = Array.new(size)
407
+ sdispls = Array.new(size)
408
+ len = rank.to_s.length * (rank+1)
409
+ size.times do |i|
410
+ sendcounts[i] = len
411
+ sdispls[i] = len * i
412
+ end
413
+ recvcounts = Array.new(size)
414
+ rdispls = [0]
415
+ str = ""
416
+ size.times do |i|
417
+ tmp = i.to_s * (i+1)
418
+ str << tmp
419
+ recvcounts[i] = tmp.length
420
+ rdispls[i+1] = rdispls[i] + recvcounts[i] if i<size-1
421
+ end
422
+ recvbuf = "?" * str.length
423
+ request = @world.Ialltoallv(sendbuf, sendcounts, sdispls, recvbuf, recvcounts, rdispls)
424
+ request.Wait
425
+ expect(recvbuf).to eql(str)
426
+ end
427
+
171
428
  it "should reduce data" do
172
429
  rank = @world.rank
173
430
  size = @world.size
@@ -182,6 +439,125 @@ describe "MPI" do
182
439
  end
183
440
  end
184
441
 
442
+ it "should reduce data without blocking" do
443
+ rank = @world.rank
444
+ size = @world.size
445
+ root = 0
446
+ bufsize = 2
447
+ sendbuf = NArray.to_na([rank]*bufsize)
448
+ recvbuf = rank == root ? NArray.new(sendbuf.typecode,bufsize) : nil
449
+ request = @world.Ireduce(sendbuf, recvbuf, MPI::Op::SUM, root)
450
+ if rank == root
451
+ ary = NArray.new(sendbuf.typecode,bufsize).fill(size*(size-1)/2.0)
452
+ request.Wait
453
+ expect(recvbuf).to be == ary
454
+ end
455
+ end
456
+
457
+ it "should reduce and scatter data" do
458
+ rank = @world.rank
459
+ size = @world.size
460
+ recvcounts = []
461
+ size.times do |i|
462
+ recvcounts[i] = i+1
463
+ end
464
+ bufsize = recvcounts.inject{|r,i| r+i}
465
+ sendbuf = NArray.to_na([rank]*bufsize)
466
+ recvbuf = NArray.new(sendbuf.typecode,recvcounts[rank])
467
+ @world.Reduce_scatter(sendbuf, recvbuf, recvcounts, MPI::Op::SUM)
468
+ ary = NArray.new(sendbuf.typecode,recvcounts[rank]).fill(size*(size-1)/2.0)
469
+ expect(recvbuf).to be == ary
470
+ end
471
+
472
+ it "should reduce and scatter data without blocking" do
473
+ rank = @world.rank
474
+ size = @world.size
475
+ recvcounts = []
476
+ size.times do |i|
477
+ recvcounts[i] = i+1
478
+ end
479
+ bufsize = recvcounts.inject{|r,i| r+i}
480
+ sendbuf = NArray.to_na([rank]*bufsize)
481
+ recvbuf = NArray.new(sendbuf.typecode,recvcounts[rank])
482
+ request = @world.Ireduce_scatter(sendbuf, recvbuf, recvcounts, MPI::Op::SUM)
483
+ ary = NArray.new(sendbuf.typecode,recvcounts[rank]).fill(size*(size-1)/2.0)
484
+ request.Wait
485
+ expect(recvbuf).to be == ary
486
+ end
487
+
488
+ it "should reduce and scatter block" do
489
+ rank = @world.rank
490
+ size = @world.size
491
+ recvcount = 2
492
+ sendbuf = NArray.to_na([rank]*(recvcount*size))
493
+ recvbuf = NArray.new(sendbuf.typecode,recvcount)
494
+ @world.Reduce_scatter_block(sendbuf, recvbuf, MPI::Op::SUM)
495
+ ary = NArray.new(sendbuf.typecode,recvcount).fill(size*(size-1)/2.0)
496
+ expect(recvbuf).to be == ary
497
+ end
498
+
499
+ it "should reduce and scatter block without blocking" do
500
+ rank = @world.rank
501
+ size = @world.size
502
+ recvcount = 2
503
+ sendbuf = NArray.to_na([rank]*(recvcount*size))
504
+ recvbuf = NArray.new(sendbuf.typecode,recvcount)
505
+ request = @world.Ireduce_scatter_block(sendbuf, recvbuf, MPI::Op::SUM)
506
+ ary = NArray.new(sendbuf.typecode,recvcount).fill(size*(size-1)/2.0)
507
+ request.Wait
508
+ expect(recvbuf).to be == ary
509
+ end
510
+
511
+ it "should scan data" do
512
+ rank = @world.rank
513
+ size = @world.size
514
+ count = 2
515
+ sendbuf = NArray.to_na([rank]*count)
516
+ recvbuf = NArray.new(sendbuf.typecode,count)
517
+ @world.Scan(sendbuf, recvbuf, MPI::Op::SUM)
518
+ ary = NArray.new(sendbuf.typecode,count).fill(rank*(rank+1)/2.0)
519
+ expect(recvbuf).to be == ary
520
+ end
521
+
522
+ it "should scan data withoug blocking" do
523
+ rank = @world.rank
524
+ size = @world.size
525
+ count = 2
526
+ sendbuf = NArray.to_na([rank]*count)
527
+ recvbuf = NArray.new(sendbuf.typecode,count)
528
+ request = @world.Iscan(sendbuf, recvbuf, MPI::Op::SUM)
529
+ ary = NArray.new(sendbuf.typecode,count).fill(rank*(rank+1)/2.0)
530
+ request.Wait
531
+ expect(recvbuf).to be == ary
532
+ end
533
+
534
+ it "should exclusively scan data" do
535
+ rank = @world.rank
536
+ size = @world.size
537
+ count = 2
538
+ sendbuf = NArray.to_na([rank]*count)
539
+ recvbuf = NArray.new(sendbuf.typecode,count)
540
+ @world.Exscan(sendbuf, recvbuf, MPI::Op::SUM)
541
+ if rank > 0
542
+ ary = NArray.new(sendbuf.typecode,count).fill(rank*(rank-1)/2.0)
543
+ expect(recvbuf).to be == ary
544
+ end
545
+ end
546
+
547
+ it "should exclusively scan data without blocking" do
548
+ rank = @world.rank
549
+ size = @world.size
550
+ count = 2
551
+ sendbuf = NArray.to_na([rank]*count)
552
+ recvbuf = NArray.new(sendbuf.typecode,count)
553
+ request = @world.Iexscan(sendbuf, recvbuf, MPI::Op::SUM)
554
+ if rank > 0
555
+ ary = NArray.new(sendbuf.typecode,count).fill(rank*(rank-1)/2.0)
556
+ request.Wait
557
+ expect(recvbuf).to be == ary
558
+ end
559
+ end
560
+
185
561
  it "should reduce data and send to all processes (allreduce)" do
186
562
  rank = @world.rank
187
563
  size = @world.size
@@ -193,10 +569,27 @@ describe "MPI" do
193
569
  expect(recvbuf).to be == ary
194
570
  end
195
571
 
572
+ it "should reduce data and send to all processes without blocking (iallreduce)" do
573
+ rank = @world.rank
574
+ size = @world.size
575
+ bufsize = 2
576
+ sendbuf = NArray.to_na([rank]*bufsize)
577
+ recvbuf = NArray.new(sendbuf.typecode,bufsize)
578
+ request = @world.Iallreduce(sendbuf, recvbuf, MPI::Op::SUM)
579
+ ary = NArray.new(sendbuf.typecode,bufsize).fill(size*(size-1)/2.0)
580
+ request.Wait
581
+ expect(recvbuf).to be == ary
582
+ end
583
+
196
584
  it "should not raise exception in calling barrier" do
197
585
  @world.Barrier
198
586
  end
199
587
 
588
+ it "should not raise exception in calling barrier without blocking" do
589
+ request = @world.Ibarrier
590
+ request.Wait
591
+ end
592
+
200
593
 
201
594
  it "shoud raise exeption" do
202
595
  expect { @world.Send("", @world.size+1, 0) }.to raise_error(MPI::ERR::RANK)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiya Nishizawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2024-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numru-narray
@@ -118,12 +118,14 @@ files:
118
118
  - lib/mpi/utils.rb
119
119
  - ruby-mpi.gemspec
120
120
  - samples/hello.rb
121
+ - samples/kmeans.rb
121
122
  - samples/narray.rb
122
123
  - samples/narray_offset.rb
124
+ - samples/pi.rb
123
125
  - spec/ruby-mpi_spec.rb
124
126
  - spec/spec_helper.rb
125
127
  - test/test_utils.rb
126
- homepage: http://github.com/seiya/ruby-mpi
128
+ homepage: http://github.com/gfd-dennou-club/ruby-mpi
127
129
  licenses:
128
130
  - MIT
129
131
  metadata: {}
@@ -142,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  - !ruby/object:Gem::Version
143
145
  version: '0'
144
146
  requirements: []
145
- rubyforge_project:
146
- rubygems_version: 2.4.8
147
+ rubygems_version: 3.2.5
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: A ruby binding of MPI