Exemple #1
0
    void task8() {
        barrier("Task 8");
        int excludeNode = size - 1;
        Group group = comm.Get_group().Excl(1, &excludeNode);
        Intracomm newComm = comm.Create(group);

        string data = "default";
        if (newComm != COMM_NULL) {
            if (newComm.Get_rank() == master) {
                data = "task8";
                printf("Process %d initialized data [%s]\n", id, &data[0]);
            }
            newComm.Barrier();
            if(id == master) {
                int len = data.length();
                newComm.Bcast(&len, 1, INTEGER, master);
                newComm.Bcast(&data[0], len + 1, CHAR, master);
                printf("Process %d sent data [%s]\n", id, &data[0]);
            } else {
                int len = 0;
                newComm.Bcast(&len, 1, INTEGER, master);
                char *resp = new char[len + 1];
                newComm.Bcast(resp, len + 1, CHAR, master);
                printf("Process %d catched data [%s]\n", id, resp);
                delete resp;
            }
            newComm.Free();
            group.Free();
        }
    }
Exemple #2
0
    void task9() {
        barrier("Task 9");
        int excludeNode = size - 1;
        int elements[] = {0, 2};
        Group group = comm.Get_group().Incl(2, elements);
        Intracomm newComm = comm.Create(group);

        int data = 5;
        int dataLen = 1;
        if (newComm != COMM_NULL) {
            if (newComm.Get_rank() == master) {
                data = 3;
                printf("Process %d initialized data [%d]\n", id, data);
            }
            int red = 0;
            newComm.Reduce(&data, &red, dataLen, INTEGER, SUM, 0);
            if (newComm.Get_rank() == master) {
                printf("Reduced data: [%d]\n", red);
            }
            newComm.Free();
            group.Free();
        }
    }