Quantcast
Channel: Intel® Software - Intel® Many Integrated Core Architecture (Intel MIC Architecture)
Viewing all articles
Browse latest Browse all 1789

Using poniters whith “into” in Intel Xeon Phi offload directive

$
0
0

According to the book " Intel Xeon Phi Coprocessor High-Performance Programming", we can move data from one variable to another. I tried to follow the example and I found it worked:

Code:

<code>

program example real , target :: a(5),b(10) a(1)=1 a(2)=2 a(3)=3 a(4)=4 a(5)=5 print *,'*************************' print *,'a:' print *, a !dir$ offload begin target (mic:0) in(a(1:5): into(b(1:5)) alloc_if(.true.) free_if(.false.) ) print *, 'b on the phi' print *, b(1:5) b=b+10 !dir$ end offload !dir$offload_transfer target(mic:0) out(b(1:5) : into(a(1:5)) alloc_if(.false.)) print *,'*************************' print *,'a:' print *, a end program example

</code>

I have an array A on the host and I copy them into an array B which is on the Xeon Phi. I add 10 to all elements in the B and then offload elements in the B on the Xeon Phi to the A on the host. the result is:

However if I use pointers, then there would be an error.

Code 2:

<code>

program example 
real , target :: a(5),b(10)
real , pointer :: a_p(:),b_p(:)

a(1)=1
a(2)=2
a(3)=3
a(4)=4
a(5)=5

a_p=>a
b_p=>b
print *,'*************************'
print *,'a:'
print *, a

!dir$ offload begin target (mic:0) in(a_p(1:5): into(b_p(1:5)) alloc_if(.true.) free_if(.false.) )
print *, 'b on the phi'
print *, b_p(1:5)
b_p=b_p+10
!dir$ end offload

!dir$offload_transfer target(mic:0) out(b_p(1:5) : into(a_p(1:5)) alloc_if(.false.))

print *,'*************************'
print *,'a:'
print *, a
end program example

</code>

result 2:

Looks like something is wrong when I try to copy things back.

Does the into support pointers? We'll need pointers to arrays in real project.

Internal Tags: 


Viewing all articles
Browse latest Browse all 1789

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>