transferring initial date to MIC

transferring initial date to MIC

Hey everyone,

I am pretty confused about how to transfer some initial data, and allocate arrays, to the MIC at the beginning of my code. For instance, one of my sources of confusion is my position array r. Here, my r is an array of structure 

type posit

  double precision :: x,y,z

  integer :: type

end type posit

type(posit), allocatable :: r(:)

r is allocated at run time when the number of particles is read in. The values of the array will change during every iteration of the code, as the particles move around. However the size of the array doesn't change, so I would like to allocate the memory on the MIC at run time. When I use the MIC, I would like the elements of r to be copied to the preallocated memory locations. However, my understanding of 

!dir$ offload target(mic:0) in(r) alloc_if(0)

is that r will not be read back from the MIC to the host, which is good for me, but the alloc_if(0) will not allocate memory and will cause the MIC to use the data from the previous runs. If this is true, is there a way for me to have the MIC allocate memory at run time, read in the values of the r whenever the mic is called, and then not deallocate. Also as my final question, what would I have to do if r was a matrix as opposed to array and also what if r was just a scalar double.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I think what you are trying to do is: allocate the memory on the host and populate it with your initial data, next allocate the memory on the coprocessor and copy the data over, then go into a loop where you repeated return to the coprocessor to work on this data (and then finally, at the end, copy the result back?)

In this case, you want to have your array r declared in a module. (You want the array to be global and not disappear when you exit an offload section on the coprocessor.) Before you get to your loop, you will want an offload directive where you specify in( r : alloc_if(.true.) free_if(.false.))  Then inside your loop, on each offload directive, you would specify nocopy( r : alloc_if(.false.) free_if(.false.)) . If you want the array back on the host at the end, then after your loop, you would have an offload directive where you specify out( r : alloc_if(.false.) free_if(.true.)) If you have more than one coprocessor, you want to specify which coprocessor to use, target(mic:0) or whichever one you are using, on each offload directive. 

You can find an example showing how do this this - and hide some of the overhead from copying the array by doing the copy asynchronously - in /opt/intel/composerxe/Samples/en_US/Fortran/mic_samples/LEO_Fortran_intro/leoF11_async.F90 on the machine where you installed the compiler.

 

Hey, thank you so much for your reply. The only thing is that I don't want to copy data back at the end. I just want to pass positions of particles to the MIC, calculate the energy, and pass the energy back to the host. The positions (data in r) is in no way changed during this. So let me see if I understand your comments:

So I would want a subroutine, called once at run time, that will allocate space on the mic. My question about this command is does this MIC know the size of array r? For instance if r were a matrix that was 1000 by 1000, would the MIC automatically know this?

!dir$ offload target(mic:0) in(r:alloc_if(.true.) free_if(.false.))

Also if I have double precision variable A,that is read in at runtime, and does not change through the simulation, to pass them to the MIC here is the command the same?

!dir$ offload target(mic:0) in(r:alloc_if(.true.) free_if(.false.)) in(A:alloc_if(.true.) free_if(.false))

 

Next when I want to call the MIC to perform the calculation. My question about the nocopy command is does the host still pass the current values of r to the MIC, and the nocopy just tells it to use the previously allocated memory space on the MIC? The values of r change between calls to the MIC, however the size of the array does not. If the values of A have not changed a tall, how do I tell the MIC to use those previous values?

!dir$ offload target(mic:0)  nocopy(r:alloc_if(.false.) free_if(.false.))

 

Leave a Comment

Please sign in to add a comment. Not a member? Join today