00001 #include <stdio.h>
00002 #include <string.h>
00003
00004 #include <moc.h>
00005 #include <internal/imoc.h>
00006 #include <internal/ppu/imoc_macros_ppu.h>
00007 #include <internal/ppu/imoc_core_ppu.h>
00008
00009 #define IMOC_BARRIER_TAG 1
00010
00011 int MOC_Barrier(MOC_Comm comm)
00012 {
00013 moc_message_envelope_t tempQueue[node_handle.queue_size] __attribute__((__aligned__(16)));
00014 moc_message_envelope_t *sourceQueueEntry;
00015 MOC_Status status;
00016 int err, qindex;
00017 unsigned int dmastatus;
00018
00019
00020 if (comm == MOC_COMM_SELF)
00021 return 0;
00022 else
00023 if (comm != MOC_COMM_WORLD)
00024 return MOC_ERR_COMM;
00025
00026
00027 if (node_handle.queue_size * sizeof(moc_message_envelope_t)
00028 > MEMCPY_GET_TRESHOLD)
00029 {
00030 err = spe_mfcio_put(moc_spu_thread_list[node_handle.comm_size - 1
00031 - moc_ppu_thread_count].speid, IMOC_LS_REMOTE_QUEUE(
00032 node_handle.comm_size - 1), tempQueue, node_handle.queue_size
00033 * sizeof(moc_message_envelope_t), 15, 0, 0);
00034 if (err)
00035 return MOC_ERR_INTERN;
00036 err = spe_mfcio_tag_status_read(
00037 moc_spu_thread_list[node_handle.comm_size - 1
00038 - moc_ppu_thread_count].speid, 0, SPE_TAG_ALL,
00039 &dmastatus);
00040 if (err)
00041 return MOC_ERR_INTERN;
00042 }
00043 else
00044 {
00045 memcpy(tempQueue, (void*) IMOC_EA_REMOTE_QUEUE(node_handle.comm_size
00046 - 1), node_handle.queue_size * sizeof(moc_message_envelope_t));
00047 }
00048
00049
00050 err = IMOC_getFreeEntry(tempQueue, IMOC_BARRIER_TAG, comm, 1, &qindex);
00051 if (err)
00052 return err;
00053
00054 tempQueue[qindex].communicator = comm;
00055 tempQueue[qindex].flags.bits.special = 1;
00056 tempQueue[qindex].flags.bits.valid = 1;
00057 tempQueue[qindex].tag = IMOC_BARRIER_TAG;
00058
00059
00060
00061 memcpy((void*) IMOC_EA_REMOTE_QUEUE_ENTRY(node_handle.comm_size - 1,
00062 qindex), &tempQueue[qindex], sizeof(moc_message_envelope_t));
00063
00064
00065 sourceQueueEntry = 0;
00066 while (sourceQueueEntry == 0)
00067 {
00068 sourceQueueEntry = IMOC_get_entry(node_handle.comm_size - 1,
00069 IMOC_BARRIER_TAG, comm, 1, &status);
00070 }
00071 sourceQueueEntry->flags.value = 0;
00072
00073 return 0;
00074 }
00075