my
$pdl
= zeroes(20);
$pdl
->share_as(
'test'
);
my
$slice
=
$pdl
(10:15)->sever;
$slice
->share_as(
'slice'
);
my
$mmap
= mapfraw(
'foo.bin'
, {
Creat
=> 1,
Datatype
=> double,
Dims
=> [50]});
$mmap
->share_as(
'mmap'
);
END {
unlink
'foo.bin'
;
unlink
'foo.bin.hdr'
;
}
my
$N_threads
= 5;
parallelize {
my
$tid
= parallel_id;
my
$pdl
= retrieve_pdls(
'test'
);
print
"Thread id $tid says the ndarray is $pdl\n"
;
parallel_sync;
my
$N_data_to_fix
=
$pdl
->nelem /
$N_threads
;
my
$idx
= sequence(
$N_data_to_fix
) *
$N_threads
+
$tid
;
$pdl
(
$idx
) .=
$tid
;
parallel_sync;
print
"After set, thread id $tid says the ndarray is $pdl\n"
;
parallel_sync;
$pdl
->set(
$tid
, 0);
parallel_sync;
print
"Thread id $tid says the ndarray is now $pdl\n"
;
}
$N_threads
;
print
"mmap is $mmap\n"
;
parallelize {
my
$tid
= parallel_id;
my
$mmap
= retrieve_pdls(
'mmap'
);
$mmap
(
$tid
) .=
$tid
;
}
$N_threads
;
print
"now mmap is $mmap\n"
;
parallelize {
my
$tid
= parallel_id;
my
$pdl
= retrieve_pdls(
'test'
);
print
"Thread id is $tid\n"
;
my
$N_data_to_fix
=
$pdl
->nelem /
$N_threads
;
my
$idx
= sequence(
$N_data_to_fix
- 1) *
$N_threads
+
$tid
;
$pdl
(
$idx
) .= -
$tid
;
my
$slice
= retrieve_pdls(
'slice'
);
$slice
(
$tid
) .= -10 *
$tid
;
}
$N_threads
;
print
"Final ndarray value is $pdl\n"
;