Example #1
0
int MPI_Waitall(int count, MPI_Request* request, MPI_Status* status)
{
    int retall = MPI_SUCCESS;

    for(int i = 0; i < count; i++)
    {
        int ret = MPI_ERR_REQUEST;
        if (request[i] != MPI_REQUEST_NULL)
        {
            centry_t* mycentry = cqueue_get_centry((long)request[i]);
            if (mycentry != NULL)
            {
                if (status == MPI_STATUS_IGNORE)
                    ret = cqueue_wait(mycentry, &request[i], MPI_STATUS_IGNORE);
               else
                   ret = cqueue_wait(mycentry, &request[i], &status[i]);
            }
            else
            {
                if (status == MPI_STATUS_IGNORE)
                    ret = PMPI_Wait(&request[i], MPI_STATUS_IGNORE);
               else
                    ret = PMPI_Wait(&request[i], &status[i]);
            }
        }
        if (ret != MPI_SUCCESS) retall = ret;
    }
    return retall;
}
Example #2
0
int MPI_Wait(MPI_Request* request, MPI_Status* status)
{
    if (*request != MPI_REQUEST_NULL)
    {
        centry_t* mycentry = cqueue_get_centry((long)*request);

        if (mycentry != NULL)
            return cqueue_wait(mycentry, request, status);
        else
            return PMPI_Wait(request, status);
    }

    /* Invalid MPI_Request. Either null or not a persistent request. */
    return MPI_ERR_REQUEST;
}
Example #3
0
int main(void)
{
	cq = cqueue_new(1024 * 80, 1000, QF_NOTIFY | QF_LOCK | QF_SHM);

    printCqueue(cq);

    pid_t pid;
    int z, worker_num = 5;
    for (z = 0; z < worker_num; z++)
    {
        if ((pid = fork()) < 0)
        {
            printf("fork");
            exit(1);
        }
        else if (pid > 0)
        {
            printf("created child process success. [pid = %d]", (int)pid);
            continue;
        }
        else
        {
            //child process
            int recvn = 0;
            struct item_bz tm_bz;
            char fname[56];
            char mbuff[256];
            FILE *fp;

            sprintf(fname, "/root/src/log_%d.txt", z);
            fp = fopen(fname, "a+");

            while (1)
            {
                if (cqueue_wait(cq) > 0)
                {
                    if (cqueue_pop(cq, &tm_bz, sizeof(struct item_bz)) < 0)
                        continue;
                    recvn++;

                    printf("worker[%d] recv: [buf=%s] [rand=%d]", z, tm_bz.buf, tm_bz.a);
                    sprintf(mbuff, "worker[%d] recv: [buf=%s] [rand=%d]\n", z, tm_bz.buf, tm_bz.a);

                    //write log to file[i];
                    fputs(mbuff, fp);
                }
            }
            printf("worker[%d] finish: [recvn=%d]", z, recvn);
            fclose(fp);
            exit(0);
        }
    }

    label: sleep(1);

    int sendn = 0;
    int inum = 10000;
    while (inum > 0)
    {
        struct item_bz ibz = {"--||||||||mmmmmm$$########", rand() % 11, &ibz};
        if (cqueue_push(cq, &ibz, sizeof (struct item_bz)) == 0)
        {
            cqueue_notify(cq);
            sendn++;
            inum--;
        }
    }

    printCqueue(cq);

    printf("master send finish: [num=%d] [sendn=%d]", inum, sendn);
    int status;
    for (z = 0; z < worker_num; z++)
    {
        wait(&status);
    }

    cqueue_free(cq);

	return 0;
}