- int i, iter, rc, gid = 1;
- int flag1, flag2, flag3, flag4;
- int temp1, temp2, temp3, temp4;
- MPI_Request req1, req2, req3, req4;
-
- if (rank == 0) {
- if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
- sprintf(errmsg,
- "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
- filename, errno, strerror(errno));
- FAIL(errmsg);
- }
- }
-
- MPI_Barrier(MPI_COMM_WORLD);
-
- switch (rank) {
- case 3:
- /* Wait for task2 to issue its read request. */
- sleep(2*WAIT_TIME);
- case 1:
- gid = 2;
- if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
- sprintf(errmsg,
- "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
- filename, errno, strerror(errno));
- FAIL(errmsg);
- }
-
- write_buf(fd, rank);
-
- MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
-
- /* Do not release the locks until task 0 is ready to watch
- for reading task only */
- MPI_Recv(&temp1, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,
- MPI_STATUS_IGNORE);
-
- if (unlock_op == CLOSE)
- rc = close(fd);
- else
- rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
- if (rc == -1) {
- sprintf(errmsg,
- "%s release GROUP_LOCK of file %s: (%d) %s.\n",
- (unlock_op == CLOSE) ? "close" : "ioctl",
- filename, errno, strerror(errno));
- FAIL(errmsg);
- }
- break;
- case 2:
- /* Give task1 a chance to request its GR lock. */
- sleep(WAIT_TIME);
-
- if (blocking_op == WRITE) {
- write_buf(fd, rank);
- lseek(fd, 0, SEEK_SET);
- }
-
- for (i = 0; i <= 3; i++)
- read_buf(fd);
-
- MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
- break;
- case 4:
- /* Give task1 & 3 a chance to queue their GR locks. */
- sleep(3*WAIT_TIME);
-
- if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {
- sprintf(errmsg,
- "ioctl GROUP_LOCK of file %s: (%d) %s.\n",
- filename, errno, strerror(errno));
- FAIL(errmsg);
- }
-
- write_buf(fd, rank);
-
- rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
- if (rc == -1) {
- sprintf(errmsg,
- "%s release GROUP_LOCK of file %s: (%d) %s.\n",
- (unlock_op == CLOSE) ? "close" : "ioctl",
- filename, errno, strerror(errno));
- FAIL(errmsg);
- }
-
- MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
- break;
- case 0:
- /* locking tasks will tell us when they complete */
- MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
- MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
- MPI_Irecv(&temp3, 1, MPI_INT, 3, 1, MPI_COMM_WORLD, &req3);
- MPI_Irecv(&temp4, 1, MPI_INT, 4, 1, MPI_COMM_WORLD, &req4);
-
- /* Make sure all tasks that should be blocked are waiting. */
- iter = MAX_WAIT_TRIES;
- do {
- iter--;
- sleep(WAIT_TIME);
- MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
- MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
- MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
- if (flag1 || flag3) {
- FAIL("GROUP (gid=2) task progressed even though"
- " GROUP (gid=1) lock is held.\n");
- }
- if (flag2) {
- FAIL("PR|PW task progressed even though "
- "GROUP (gid=1) lock is still held\n");
- }
- } while (iter);
-
- /* Wait for task4 to signal it has completed. */
- iter = MAX_WAIT_TRIES;
- do {
- iter--;
- if (!iter) {
- FAIL("2nd task GROUP(gid=1) not progressing\n");
- }
- sleep(WAIT_TIME);
- MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
- MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
- MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
- MPI_Test(&req4, &flag4, MPI_STATUS_IGNORE);
- if (flag1 || flag3) {
- FAIL("GROUP (gid=2) task progressed even though"
- " GROUP (gid=1) lock is held.\n");
- }
- if (flag2) {
- FAIL("PR|PW task progressed even though "
- "GROUP (gid=1) lock is still held\n");
- }
- } while (!flag4);
-
- write_buf(fd, rank);
-
- /* Now let's release first lock */
- if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {
- sprintf(errmsg, "ioctl GROUP_UNLOCK of file %s "
- "returned %d", filename, rc);
- FAIL(errmsg);
- }
-
- /* Wait for task1 & 3 to signal they have their lock. */
- iter = MAX_WAIT_TRIES;
- do {
- iter--;
- if (!iter) {
- FAIL("GROUP(gid=2) tasks not progressing\n");
- }
- sleep(WAIT_TIME);
- MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
- MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
- MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
- if (flag2) {
- fprintf(stderr, "task2 %d\n", flag2);
- FAIL("PR task progressed even though GROUP lock"
- " was on the queue task\n");
- }
- } while (!(flag1 && flag3));
-
- /* Make sure task2 is still waiting. */
- iter = MAX_WAIT_TRIES;
- do {
- iter--;
- sleep(WAIT_TIME);
- MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
- if (flag2) {
- FAIL("PR task progressed even though GR(gid=2) "
- "lock was active.\n");
- }
- } while (iter);
-
- /* Tell task1 & 3 to release their GR(gid=2) lock. */
- MPI_Send(&gid, 1, MPI_INT, 1, 1, MPI_COMM_WORLD);
- MPI_Send(&gid, 1, MPI_INT, 3, 1, MPI_COMM_WORLD);
-
- /* Wait for task2 (PR) to complete. */
- iter = MAX_WAIT_TRIES;
- do {
- iter--;
- if (!iter) {
- FAIL("reading task is not progressing even "
- "though GROUP locks are released\n");
- break;
- }
- sleep(WAIT_TIME);
- MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
- } while (!flag3);
- break;
- }
+ int i, iter, rc, gid = 1;
+ int flag1, flag2, flag3, flag4;
+ int temp1, temp2, temp3, temp4;
+ MPI_Request req1, req2, req3, req4;
+
+ if (rank == 0) {
+ rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
+ if (rc == -1)
+ FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
+ filename, errno, strerror(errno));
+ }
+
+ MPI_Barrier(MPI_COMM_WORLD);
+
+ switch (rank) {
+ case 3:
+ /* Wait for task2 to issue its read request. */
+ sleep(2 * WAIT_TIME);
+ case 1:
+ gid = 2;
+ rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
+ if (rc == -1)
+ FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
+ filename, errno, strerror(errno));
+
+ write_buf(fd, rank);
+
+ MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
+
+ /*
+ * Do not release the locks until task 0 is ready to watch
+ * for reading task only
+ */
+ MPI_Recv(&temp1, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,
+ MPI_STATUS_IGNORE);
+
+ if (unlock_op == CLOSE)
+ rc = close(fd);
+ else
+ rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
+ if (rc == -1)
+ FAILF("%s release GROUP_LOCK of file %s: (%d) %s.\n",
+ (unlock_op == CLOSE) ? "close" : "ioctl",
+ filename, errno, strerror(errno));
+ break;
+ case 2:
+ /* Give task1 a chance to request its GR lock. */
+ sleep(WAIT_TIME);
+
+ if (blocking_op == WRITE) {
+ write_buf(fd, rank);
+ lseek(fd, 0, SEEK_SET);
+ }
+
+ for (i = 0; i <= 3; i++)
+ read_buf(fd);
+
+ MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
+ break;
+ case 4:
+ /* Give task1 & 3 a chance to queue their GR locks. */
+ sleep(3 * WAIT_TIME);
+
+ rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
+ if (rc == -1)
+ FAILF("ioctl GROUP_LOCK of file %s: (%d) %s.\n",
+ filename, errno, strerror(errno));
+
+ write_buf(fd, rank);
+
+ rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
+ if (rc == -1)
+ FAILF("%s release GROUP_LOCK of file %s: (%d) %s.\n",
+ (unlock_op == CLOSE) ? "close" : "ioctl",
+ filename, errno, strerror(errno));
+
+ MPI_Send(&gid, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
+ break;
+ case 0:
+ /* locking tasks will tell us when they complete */
+ MPI_Irecv(&temp1, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, &req1);
+ MPI_Irecv(&temp2, 1, MPI_INT, 2, 1, MPI_COMM_WORLD, &req2);
+ MPI_Irecv(&temp3, 1, MPI_INT, 3, 1, MPI_COMM_WORLD, &req3);
+ MPI_Irecv(&temp4, 1, MPI_INT, 4, 1, MPI_COMM_WORLD, &req4);
+
+ /* Make sure all tasks that should be blocked are waiting. */
+ iter = MAX_WAIT_TRIES;
+ do {
+ iter--;
+ sleep(WAIT_TIME);
+ MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
+ MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
+ MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
+ if (flag1 || flag3)
+ FAIL("GROUP (gid=2) task progressed even though GROUP (gid=1) lock is held.\n");
+ if (flag2)
+ FAIL("PR|PW task progressed even though GROUP (gid=1) lock is still held\n");
+ } while (iter);
+
+ /* Wait for task4 to signal it has completed. */
+ iter = MAX_WAIT_TRIES;
+ do {
+ iter--;
+ if (!iter)
+ FAIL("2nd task GROUP(gid=1) not progressing\n");
+
+ sleep(WAIT_TIME);
+ MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
+ MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
+ MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
+ MPI_Test(&req4, &flag4, MPI_STATUS_IGNORE);
+ if (flag1 || flag3)
+ FAIL("GROUP (gid=2) task progressed even though GROUP (gid=1) lock is held.\n");
+ if (flag2)
+ FAIL("PR|PW task progressed even though GROUP (gid=1) lock is still held\n");
+ } while (!flag4);
+
+ write_buf(fd, rank);
+
+ /* Now let's release first lock */
+ rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
+ if (rc == -1)
+ FAILF("ioctl GROUP_UNLOCK of file %s returned %d",
+ filename, rc);
+
+ /* Wait for task1 & 3 to signal they have their lock. */
+ iter = MAX_WAIT_TRIES;
+ do {
+ iter--;
+ if (!iter)
+ FAIL("GROUP(gid=2) tasks not progressing\n");
+
+ sleep(WAIT_TIME);
+ MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);
+ MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
+ MPI_Test(&req3, &flag3, MPI_STATUS_IGNORE);
+ if (flag2) {
+ fprintf(stderr, "task2 %d\n", flag2);
+ FAIL("PR task progressed even though GROUP lock was on the queue task\n");
+ }
+ } while (!(flag1 && flag3));
+
+ /* Make sure task2 is still waiting. */
+ iter = MAX_WAIT_TRIES;
+ do {
+ iter--;
+ sleep(WAIT_TIME);
+ MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
+ if (flag2)
+ FAIL("PR task progressed even though GR(gid=2) lock was active.\n");
+ } while (iter);
+
+ /* Tell task1 & 3 to release their GR(gid=2) lock. */
+ MPI_Send(&gid, 1, MPI_INT, 1, 1, MPI_COMM_WORLD);
+ MPI_Send(&gid, 1, MPI_INT, 3, 1, MPI_COMM_WORLD);
+
+ /* Wait for task2 (PR) to complete. */
+ iter = MAX_WAIT_TRIES;
+ do {
+ iter--;
+ if (!iter) {
+ FAIL("reading task is not progressing even though GROUP locks are released\n");
+ break;
+ }
+ sleep(WAIT_TIME);
+ MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);
+ } while (!flag3);
+ break;
+ }